zhihui
路人甲
路人甲
  • 注册日期2008-11-22
  • 发帖数1
  • QQ
  • 铜币108枚
  • 威望0点
  • 贡献值0点
  • 银元0个
阅读:1275回复:0

[求助][求助]拜求 gis 大大以及各位前輩們...麻煩

楼主#
更多 发布于:2008-12-14 20:08
<P>各位前輩們...我想請求一點問題...能否麻煩您們替我解疑一下 ?</P>
<P>我模擬了 Geotools 的原始碼 MapViewer.java 將其 shapfile 的部分更改為 xml ...</P>
<P>但是我卻一再的碰到瓶頸無法突破...所以要請求各位前輩們的幫忙...</P>
<P>我有依照原始碼重新編寫過...</P>
<P>能夠順利的讀取 shapfile 以達到 render...</P>
<P>但是因為我的目標是 xml ... </P>
<P>所幸將程式更改為如下(也包含了 xml 的內容部分)...但是卻碰到了難解的問題...</P>
<P>能否拜託各位前輩們給我一些提點與指教...</P>
<P>拜託了...</P>
<P><FONT color=#ff0000 size=4><STRONG>程式碼如下所示 :</STRONG></FONT></P>
<P>
<HR>
</P>
<P>import java.awt.BorderLayout;<BR>import java.awt.Container;<BR>import java.io.File;<BR>import java.io.IOException;<BR>import java.net.MalformedURLException;<BR>import java.net.URI;<BR>import java.net.URL;<BR>import java.util.HashMap;</P>
<P>import javax.swing.Action;<BR>import javax.swing.JButton;<BR>import javax.swing.JFrame;<BR>import javax.swing.JLabel;<BR>import javax.swing.JToolBar;<BR>import javax.swing.WindowConstants;</P>
<P>import org.geotools.data.FeatureSource;<BR>import org.geotools.data.AbstractDataStore;<BR>import org.geotools.data.gml.FileGMLDataStore;<BR>import org.geotools.data.Query;<BR>import org.geotools.factory.CommonFactoryFinder;<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;</P>
<P>import com.vividsolutions.jts.geom.Envelope;</P>
<P><BR>public class TryMap {<BR> JButton jb;<BR>    JFrame jf;<BR>    JMapPane jmp;<BR>    JToolBar jtb;</P>
<P> public TryMap () {<BR><BR>  jf = new JFrame ("囧 Map Viewer 囧");<BR>  jf.setBounds (20,20,450,200);<BR>  jf.setDefaultCloseOperation (WindowConstants.EXIT_ON_CLOSE);<BR>  <BR>  Container container = jf.getContentPane ();<BR>  container.setLayout (new BorderLayout ());<BR>  <BR>  jmp = new JMapPane ();<BR>  jtb = new JToolBar ();</P>
<P>  Action zoomIn = new ZoomInAction (jmp);<BR>  Action zoomOut = new ZoomOutAction (jmp);<BR>  Action pan = new PanAction (jmp);<BR>  Action select = new SelectAction (jmp);<BR>  Action reset = new ResetAction (jmp);<BR>  jtb.add (zoomIn);<BR>  jtb.add (zoomOut);<BR>  jtb.add (pan);<BR>  jtb.addSeparator();<BR>  jtb.add (select);<BR>  jtb.addSeparator();<BR>  jtb.add (reset);</P>
<P>  container.add (jtb,BorderLayout.NORTH);</P>
<P>  jmp.setSize (400,200);<BR>  container.add (jmp,BorderLayout.CENTER);</P>
<P>  jf.setVisible (true);<BR> }<BR> <BR> public void load (URI udir, int featureBufferSize, int timeout, URL url) throws Exception {<BR>  AbstractDataStore ads = new FileGMLDataStore(udir, featureBufferSize, timeout);<BR>  <BR>  FeatureSource fs = ads.getFeatureSource ("Taiwan");<BR>  System.out.println ("Features: " + fs.getFeatures());<BR>  System.out.println ("Count: " + fs.getCount(Query.ALL));<BR>  System.out.println ("Schema: " + fs.getSchema());<BR>  Envelope envelope = fs.getBounds();<BR>  jmp.setMapArea(envelope);</P>
<P>  StyleFactory sf = CommonFactoryFinder.getStyleFactory (null);</P>
<P>  SLDParser sldp = new SLDParser (sf, url);<BR>  Style[] style = sldp.readXML ();<BR>  </P>
<P>  MapContext mc = new DefaultMapContext (DefaultGeographicCRS.WGS84);<BR>  mc.addLayer (fs, style[0]);<BR>  mc.getLayerBounds ();<BR>  jmp.setHighlightLayer (mc.getLayer (0));<BR>  jmp.setSelectionLayer (mc.getLayer (0));<BR>  GTRenderer gtr;<BR>  if (true) { <BR>   gtr = new StreamingRenderer ();<BR>   HashMap hints = new HashMap ();<BR>   hints.put ("memoryPreloadingEnabled", Boolean.TRUE);<BR>   gtr.setRendererHints (hints);<BR>  }<BR>  else {<BR>   gtr = new StreamingRenderer ();<BR>   HashMap hints = new HashMap ();<BR>   hints.put ("memoryPreloadingEnabled", Boolean.FALSE);<BR>   gtr.setRendererHints (hints);<BR>  }<BR>  jmp.setRenderer(gtr);<BR>  jmp.setContext(mc);</P>
<P>  jf.repaint ();<BR>  System.out.println ("end");<BR> }</P>
<P> public static void main(String[] args) {<BR>  <BR>  TryMap tm = new TryMap ();<BR>  File xmlFile = new File ("C:\\", "Taiwan.xml");<BR>  File sldFile = new File ("C:\\", "Taiwan.sld");<BR>  <BR>  URI xmlFileURI = null;<BR>  URL sldFileURL = null;<BR>  try {<BR>//   xmlFileURI = xmlFile.getParentFile().toURI ();<BR>   xmlFileURI = xmlFile.toURI ();<BR>   sldFileURL = sldFile.toURI ().toURL ();<BR>  }<BR>  catch (SecurityException e) {<BR>   e.printStackTrace ();<BR>   System.exit (1);<BR>  }<BR>  catch (MalformedURLException e) {<BR>   e.printStackTrace();<BR>  }</P>
<P>  try {<BR>   tm.load (xmlFileURI, 10, 100000, sldFileURL);<BR>  }<BR>  catch (Exception e) {<BR>   e.printStackTrace ();<BR>   System.exit (1);<BR>  }<BR> }</P>
<P>}<BR>/* ********************** */</P>
<P>
<HR>
</P>
<P><BR><FONT color=#ff0000 size=4><STRONG>XML 內容如下 :</STRONG></FONT></P>
<P>
<HR>
</P>
<P><BR><?xml version='1.0' encoding="ISO-8859-1" ?><BR><wfs:FeatureCollection<BR>   xmlns:ms="<a href="http://mapserver.gis.umn.edu/mapserver" target="_blank" >http://mapserver.gis.umn.edu/mapserver</A>"<BR>   xmlns:wfs="<a href="http://www.opengis.net/wfs" target="_blank" >http://www.opengis.net/wfs</A>"<BR>   xmlns:gml="<a href="http://www.opengis.net/gml" target="_blank" >http://www.opengis.net/gml</A>"<BR>   xmlns:ogc="<a href="http://www.opengis.net/ogc" target="_blank" >http://www.opengis.net/ogc</A>"<BR>   xmlns:xsi="<a href="http://www.w3.org/2001/XMLSchema-instance" target="_blank" >http://www.w3.org/2001/XMLSchema-instance</A>"<BR>   xsi:schemaLocation="<a href="http://www.opengis.net/wfs" target="_blank" >http://www.opengis.net/wfs</A> <a href="http://schemas.opengis.net/wfs/1.0.0/WFS-basic.xsd" target="_blank" >http://schemas.opengis.net/wfs/1.0.0/WFS-basic.xsd</A> <BR>                       <a href="http://mapserver.gis.umn.edu/mapserver" target="_blank" >http://mapserver.gis.umn.edu/mapserver</A> <a href="http://w2.vliz.be/cgi-bin/mapserv.exe?map=/websites/vliz/htdocs/vmdcdata/marbound/mapfiles/marbound2.map;amp;SERVICE=WFS;amp;VERSION=1.0.0;amp;REQUEST=DescribeFeatureType;amp;TYPENAME=eez;amp;OUTPUTFORMAT=XMLSCHEMA" target="_blank" >http://w2.vliz.be/cgi-bin/mapserv.exe?map=/websites/vliz/htdocs/vmdcdata/marbound/mapfiles/marbound2.map;amp;SERVICE=WFS;amp;VERSION=1.0.0;amp;REQUEST=DescribeFeatureType;amp;TYPENAME=eez;amp;OUTPUTFORMAT=XMLSCHEMA</A>"><BR>      <gml:boundedBy><BR>       <gml:Box srsName="EPSG:4326"><BR>        <gml:coordinates>114.324550,17.366870 123.609938,26.950310</gml:coordinates><BR>       </gml:Box><BR>      </gml:boundedBy><BR>    <gml:featureMember><BR>      <ms:eez><BR>        <gml:boundedBy><BR>         <gml:Box srsName="EPSG:4326"><BR>          <gml:coordinates>114.324550,17.366870 123.609938,26.950310</gml:coordinates><BR>         </gml:Box><BR>        </gml:boundedBy><BR>        <ms:msGeometry><BR>        <gml:MultiPolygon srsName="EPSG:4326"><BR>        <gml:polygonMember><BR>          <gml:Polygon><BR>            <gml:outerBoundaryIs><BR>              <gml:LinearRing><BR>                <gml:coordinates>114.324550,19.027920 114.697751,19.859903 114.778809,20.039002 114.887922,20.279208 115.087246,20.706584 115.088112,20.708442 115.114112,20.764180 115.470460,21.324129 115.491424,21.356305 115.570997,21.396960 116.202872,21.716502 116.345476,21.752007 116.570074,21.807941 116.676962,21.834389 116.750429,21.840403 117.003736,21.860487 117.063511,21.865260 117.393140,21.891559 117.451785,21.896277 117.921691,21.805302 118.054836,21.779483 118.191847,21.752205 118.301130,21.730446 118.304120,22.043049 118.320571,22.413782 118.323470,22.479882 118.328067,22.571504 118.318334,22.955758 118.432602,23.292317 118.439460,23.310903 118.446024,23.324676 118.449931,23.332885 118.478182,23.400709 118.478805,23.402213 118.503762,23.462422 118.689565,23.685071 118.853415,23.883306 118.865274,23.891223 118.877883,23.904473 118.879341,23.906060 118.958041,23.991383 118.989453,24.029999 119.046126,24.106785 119.046782,24.107390 119.074532,24.132900 119.278010,24.327867 119.328766,24.350969 119.592591,24.382445 119.717973,24.397333 119.789120,24.403118 119.816608,24.424927 119.838021,24.445232 119.879124,24.484295 119.902471,24.509680 119.946072,24.564278 119.977441,24.611744 120.046612,24.715377 120.077557,24.765786 120.077983,24.766233 120.086085,24.774733 120.149883,24.844810 120.180824,24.879798 120.212113,24.903994 120.244884,24.929272 120.337672,25.000954 120.379396,25.038336 120.401668,25.067977 120.403014,25.069776 120.410090,25.079266 120.453215,25.138713 120.470401,25.168309 120.502715,25.224171 120.527220,25.277731 120.535351,25.295661 120.551339,25.331731 120.557659,25.346226 120.562414,25.357221 120.566276,25.363169 120.579563,25.382756 120.652761,25.494037 120.665750,25.513893 120.694091,25.557668 120.708212,25.579599 120.710279,25.583059 120.721973,25.602592 120.786042,25.635513 120.857362,25.672995 120.879884,25.685066 120.936666,25.720387 121.016722,25.795493 121.033788,25.812237 121.175479,25.958567 121.210199,25.984348 121.333498,26.078849 121.353970,26.113542 121.506825,26.372418 121.510719,26.378981 121.615305,26.450057 121.960285,26.683875 122.009943,26.717625 122.078488,26.745730 122.446579,26.896015 122.607523,26.950310 122.646803,26.780703 122.699845,26.550941 122.726955,26.315013 122.788135,25.761119 122.788313,25.759470 122.788410,25.758570 122.799735,25.651934 122.838930,25.485668 122.894103,25.255099 122.900097,25.229875 122.746033,25.123491 122.745780,25.123317 122.668826,25.012092 122.666591,25.008852 122.575747,24.875529 122.565647,24.860940 122.531617,24.814228 122.416188,24.577619 122.401275,24.493621 122.396277,24.445099 122.396163,24.443998 122.392999,24.413983 122.382002,24.150546 122.402802,23.998613 122.409450,23.949155 122.410048,23.944668 122.413093,23.927570 122.420561,23.886336 122.479943,23.741603 122.498256,23.697401 122.522595,23.649015 122.550705,23.594627 122.585222,23.536244 122.635314,23.449853 122.652485,23.423633 122.654909,23.419881 122.682417,23.379820 122.749826,23.292118 122.821256,23.115487 122.832889,23.075791 123.005114,22.833457 123.113335,22.682504 123.129698,22.659611 123.130130,22.659007 123.224418,22.527030 123.373234,22.390114 123.422552,22.346462 123.521649,22.258140 123.530919,22.249878 123.585421,22.201050 123.609938,22.178960 122.948964,21.951612 122.946577,21.950777 122.944192,21.949943 122.941949,21.949157 122.939707,21.948371 122.936211,21.947144 122.318812,21.728531 122.211069,21.690443 121.947944,21.597530 121.889598,21.576919 121.794442,21.542999 121.603593,21.474300 121.270764,21.352447 121.262253,21.342120 121.231545,21.304584 121.136678,21.198144 121.060726,21.138117 121.033923,21.119187 120.935775,21.049446 120.656177,20.856154 120.559562,20.788833 120.464955,20.715397 120.232685,20.535336 120.055240,20.430556 119.767537,20.366913 119.709463,20.353953 119.394503,20.283606 119.282567,20.265436 119.105210,20.268598 119.080222,20.269259 119.048241,20.219612 118.877672,19.954378 118.875312,19.950707 118.871416,19.944672 118.839174,19.894783 118.496989,19.366753 118.108882,18.764546 118.098550,18.751249 117.795807,18.389793 117.451344,18.014331 117.432658,17.993957 116.981614,17.704278 116.717969,17.534549 116.552993,17.420598 116.479216,17.366870 116.279876,17.384671 116.133429,17.406528 116.105703,17.437603 116.006310,17.534741 115.768375,17.748402 115.475285,18.010734 115.447484,18.035608 114.646752,18.744807 114.600526,18.785526 114.324550,19.027920 </gml:coordinates><BR>              </gml:LinearRing><BR>            </gml:outerBoundaryIs><BR>            <gml:innerBoundaryIs><BR>              <gml:LinearRing><BR>                <gml:coordinates>120.055119,23.073881 120.049146,23.060827 120.053937,23.044372 120.064419,23.034999 120.107755,23.013609 120.135537,23.022772 120.163882,22.953609 120.167482,22.908045 120.172764,22.881663 120.199709,22.786945 120.206382,22.773327 120.228673,22.736727 120.251519,22.682354 120.238591,22.660827 120.240255,22.649436 120.244709,22.640272 120.253328,22.628054 120.267909,22.612499 120.296100,22.596936 120.312764,22.572499 120.321928,22.554445 120.329991,22.536109 120.327855,22.524945 120.303700,22.550872 120.307082,22.540436 120.328600,22.519445 120.343600,22.505554 120.379564,22.481936 120.389437,22.478463 120.416900,22.482499 120.426091,22.470827 120.444700,22.453327 120.478582,22.431109 120.488591,22.429163 120.505546,22.422499 120.553309,22.382772 120.574573,22.364163 120.610264,22.312772 120.620528,22.295272 120.629437,22.277499 120.674991,22.181936 120.677755,22.171936 120.691091,22.115272 120.693037,22.104445 120.686373,22.053609 120.699009,21.943327 120.709019,21.932218 120.719564,21.927909 120.824155,21.927772 120.881364,22.036945 120.884719,22.098054 120.879428,22.232563 120.873028,22.274999 120.871373,22.291945 120.872755,22.320136 120.878591,22.341381 120.955555,22.535827 120.969709,22.568327 121.014428,22.634990 121.030273,22.656381 121.079437,22.709163 121.108319,22.722218 121.119137,22.724718 121.128864,22.728054 121.137500,22.735272 121.168055,22.762499 121.259164,22.899999 121.355555,23.087499 121.453046,23.327218 121.473309,23.401109 121.475809,23.414718 121.476328,23.422418 121.496373,23.485272 121.536928,23.701381 121.596364,23.899999 121.611364,23.983327 121.616091,24.034163 121.609155,24.041663 121.602619,24.058327 121.606228,24.083190 121.659419,24.184718 121.676091,24.204990 121.744982,24.286381 121.753055,24.292772 121.772491,24.301663 121.759637,24.330827 121.776655,24.414163 121.780546,24.426381 121.796100,24.448327 121.803591,24.455554 121.816673,24.463881 121.831100,24.470827 121.839709,24.476381 121.853046,24.533609 121.853319,24.563609 121.849428,24.592218 121.843600,24.606381 121.828328,24.614436 121.821109,24.624718 121.817209,24.637218 121.800809,24.745272 121.799709,24.756663 121.805255,24.789999 121.813873,24.834999 121.818191,24.850272 121.828328,24.866936 121.880528,24.930963 121.913882,24.959999 121.947200,24.976381 121.969509,24.985036 121.978319,24.986936 121.994982,24.995272 122.000409,25.007218 121.881655,25.114718 121.788600,25.126581 121.734709,25.138881 121.681273,25.168663 121.636655,25.214436 121.616928,25.249436 121.608873,25.259163 121.598037,25.267218 121.583328,25.275827 121.563182,25.283609 121.515273,25.282218 121.478319,25.270418 121.442746,25.243881 121.435255,25.236663 121.396519,25.189018 121.395819,25.178327 121.444119,25.134745 121.441109,25.129099 121.418055,25.149163 121.409419,25.155272 121.389364,25.158263 121.373719,25.150972 121.363037,25.143327 121.338591,25.132499 121.310528,25.126109 121.275873,25.118909 121.223600,25.115554 121.194700,25.109999 121.060537,25.048609 121.009164,25.008890 121.001664,25.001663 120.958700,24.933045 120.951391,24.923327 120.921100,24.875827 120.903319,24.836663 120.871600,24.739990 120.862482,24.739027 120.751391,24.647499 120.696219,24.598609 120.665819,24.533054 120.656646,24.511109 120.650546,24.493881 120.642764,24.479163 120.628591,24.463609 120.594437,24.427990 120.578600,24.410272 120.571664,24.402218 120.558873,24.385272 120.544982,24.362218 120.509282,24.289299 120.476382,24.210272 120.471909,24.193045 120.427200,24.149999 120.421100,24.141109 120.363037,24.048336 120.312473,23.953327 120.283864,23.898327 120.278700,23.889072 120.239700,23.829999 120.221919,23.819445 120.194837,23.783327 120.115537,23.631381 120.111228,23.617081 120.115537,23.568881 120.123873,23.514163 120.125164,23.508754 120.128864,23.493327 120.134719,23.466109 120.147764,23.394718 120.143946,23.322499 120.130000,23.317499 120.109709,23.286945 120.099719,23.266936 120.083328,23.228054 120.056509,23.155963 120.057346,23.144990 120.064846,23.138045 120.084855,23.133609 120.092764,23.126936 120.097555,23.087909 120.086928,23.079163 120.067491,23.079163 120.055119,23.073881 </gml:coordinates><BR>              </gml:LinearRing><BR>            </gml:innerBoundaryIs><BR>          </gml:Polygon><BR>        </gml:polygonMember><BR>        </gml:MultiPolygon><BR>        </ms:msGeometry><BR>        <ms:EEZ>Taiwanese Exclusive Economic Zone</ms:EEZ><BR>        <ms:Country>Taiwan</ms:Country><BR>        <ms:ID>14</ms:ID><BR>        <ms:Sovereign>Taiwan</ms:Sovereign><BR>        <ms:Remarks>Taiwans sovereignity is disputed by China</ms:Remarks><BR>        <ms:Sov_ID>14</ms:Sov_ID><BR>      </ms:eez><BR>    </gml:featureMember><BR></wfs:FeatureCollection></P>

<P>
<HR>
</P>
<P><BR><FONT color=#ff0000 size=4><STRONG>Error 如下 :</STRONG></FONT></P>
<P>
<HR>
</P>
<P><BR>Features: <a href="mailtorg.geotools.data.DefaultFeatureResults@14df764" target="_blank" >org.geotools.data.DefaultFeatureResults@14df764</A>                       </P>
<P>Count: -1</P>
<P>Schema: DefaultFeatureType [name=eez , namespace=http://www.opengis.net/gml , abstract=false , types=(DefaultAttributeType [name=msGeometry , type=class com.vividsolutions.jts.geom.Geometry , nillable=true, min=0, max=0],DefaultAttributeType [name=EEZ , type=class java.lang.String , nillable=false, min=1, max=1],DefaultAttributeType [name=Country , type=class java.lang.String , nillable=false, min=1, max=1],DefaultAttributeType [name=ID , type=class java.lang.String , nillable=false, min=1, max=1],DefaultAttributeType [name=Sovereign , type=class java.lang.String , nillable=false, min=1, max=1],DefaultAttributeType [name=Remarks , type=class java.lang.String , nillable=false, min=1, max=1],DefaultAttributeType [name=Sov_ID , type=class java.lang.String , nillable=false, min=1, max=1],)]</P>
<P>java.lang.NullPointerException</P>
<P>at com.vividsolutions.jts.geom.Envelope.init(Envelope.java:254)</P>
<P>at com.vividsolutions.jts.geom.Envelope.<init>(Envelope.java:186)</P>
<P>at org.geotools.geometry.jts.ReferencedEnvelope.<init>(ReferencedEnvelope.java:167)</P>
<P>at org.geotools.map.DefaultMapLayer.getBounds(DefaultMapLayer.java:405)</P>
<P>at org.geotools.map.DefaultMapContext.getLayerBounds(DefaultMapContext.java:559)</P>
<P>at TryMap.load(TryMap.java:146)</P>
<P>at TryMap.main(TryMap.java:192)              </P>
<P>
<HR>
</P>
<P><BR>不管如何...小弟我先在此感謝各位的幫忙了!!</P>
<P>謝謝您們...<BR></P>
喜欢0 评分0
游客

返回顶部