阅读:4117回复:3
[求助]关于JAVA显示.shp格式的地图。。
我有一张.shp格式的地图里面有几十个点,可是我在JAVA里面显示时只能显示一个点,是什么原因呢?请大家指点一下,谢谢!
|
|
1楼#
发布于:2009-08-17 10:49
帮顶<img src="images/post/smile/dvbbs/em08.gif" />
|
|
2楼#
发布于:2007-12-04 13:25
<P>学习了!!</P>
<P>我正要做j2ee结构的webgis 现在也在学习 </P> <P>我参考的是 Topmap 组件 在Topmap中shp格式的是可以直接读取的</P> <P>我还没有时间研究里面的机制是如何读取的</P> <P> 帮顶 </P><img src="images/post/smile/dvbbs/em08.gif" /> |
|
3楼#
发布于:2007-11-14 11:12
<P>以下代码来自于GeoTools示例程序:</P>
<P>import java.awt.BorderLayout;<BR>import java.awt.Container;<BR>import java.io.File;<BR>import java.net.MalformedURLException;<BR>import java.net.URL;</P> <P>import javax.swing.Action;<BR>import javax.swing.JFrame;<BR>import javax.swing.JScrollPane;<BR>import javax.swing.JToolBar;</P> <P>import org.geotools.data.FeatureSource;<BR>import org.geotools.data.shapefile.ShapefileDataStore;<BR>import org.geotools.gui.swing.JMapPane;<BR>import org.geotools.gui.swing.PanAction;<BR>import org.geotools.gui.swing.ResetAction;<BR>import org.geotools.gui.swing.SelectAction;<BR>import org.geotools.gui.swing.ZoomInAction;<BR>import org.geotools.gui.swing.ZoomOutAction;<BR>import org.geotools.map.DefaultMapContext;<BR>import org.geotools.map.MapContext;<BR>import org.geotools.referencing.crs.DefaultGeographicCRS;<BR>import org.geotools.renderer.GTRenderer;<BR>import org.geotools.renderer.lite.StreamingRenderer;<BR>import org.geotools.styling.SLDParser;<BR>import org.geotools.styling.Style;<BR>import org.geotools.styling.StyleFactory;<BR>import org.geotools.styling.StyleFactoryFinder;</P> <P>import com.vividsolutions.jts.geom.Envelope;</P> <P><BR>public class JMapPaneDemo extends JFrame {<BR> <BR> private static final long serialVersionUID = 1L;<BR> <BR> private JToolBar toolBar = new JToolBar();<BR> private JMapPane mapPane = new JMapPane();<BR> <BR> public JMapPaneDemo() {<BR> Container contentPane = getContentPane();<BR> contentPane.setLayout(new BorderLayout());<BR> <BR> contentPane.add(toolBar, BorderLayout.NORTH); <BR> contentPane.add(mapPane, BorderLayout.CENTER);<BR> <BR> Action zoomIn = new ZoomInAction(mapPane);<BR> Action zoomOut = new ZoomOutAction(mapPane);<BR> Action pan = new PanAction(mapPane);<BR> Action select = new SelectAction(mapPane);<BR> Action reset = new ResetAction(mapPane);<BR> toolBar.add(zoomIn);<BR> toolBar.add(zoomOut);<BR> toolBar.add(pan);<BR> toolBar.add(select);<BR> toolBar.add(reset);<BR> <BR> setBounds(20, 20, 600, 400);<BR> setVisible(true);<BR> }<BR> <BR> public void load(URL shapefile, URL sld)throws Exception {<BR> ShapefileDataStore shapefileDataStore = new ShapefileDataStore(shapefile);<BR> FeatureSource featureSource = shapefileDataStore.getFeatureSource();<BR> Envelope mapArea = featureSource.getBounds();<BR> mapPane.setMapArea(mapArea);<BR> <BR> StyleFactory styleFactory = StyleFactoryFinder.createStyleFactory();<BR> SLDParser sldParser = new SLDParser(styleFactory, sld);<BR> Style[] styles = sldParser.readXML();<BR> <BR> MapContext mapContext = new DefaultMapContext(DefaultGeographicCRS.WGS84);<BR> mapContext.addLayer(featureSource, styles[0]);<BR> mapContext.getLayerBounds();<BR> mapPane.setHighlightLayer(mapContext.getLayer(0));<BR> <BR> GTRenderer gtRenderer;<BR> gtRenderer = new StreamingRenderer();<BR> mapPane.setRenderer(gtRenderer);<BR> mapPane.setContext(mapContext);<BR> <BR> repaint();<BR> }<BR> <BR> public static void main(String[] args) {<BR> JMapPaneDemo application = new JMapPaneDemo();<BR> application.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);<BR> <BR> File shapefile = new File("countries.shp");<BR> File sld = new File("countries.sld");<BR> URL shapefileURL = null;<BR> URL sldURL = null;<BR> try {<BR> shapefileURL = shapefile.toURL();<BR> sldURL = sld.toURL();<BR> } catch (MalformedURLException e) {<BR> e.printStackTrace();<BR> }<BR> try {<BR> application.load(shapefileURL, sldURL);<BR> } catch (Exception e) {<BR> e.printStackTrace();<BR> }<BR> }<BR>}<BR></P> |
|
|