Screenshot instructions:
Windows
Mac
Red Hat Linux
Ubuntu
Click URL instructions:
Right-click on ad, choose "Copy Link", then paste here →
(This may not be possible with some types of ads)
From: kapil <kapilsharma047@gm...> - 2013-01-22 09:28:38
|
Hi List, I want to show a map on JmapPane, but i found exception when i run the code. Here is my code: ResultSet res = stmt.executeQuery(sql); SimpleFeatureCollection col = org.geotools.feature.FeatureCollections.newCollection(); while (res.next()) { col.add(PolygonFeatureHelper.createPolyFeature(new WKTReader().read(res.getString("the_geom")), res.getString("kide"))); } StyleBuilder sb = new StyleBuilder(); MapStyleSetings mapSty = new MapStyleSetings(); //.............................. Irrelevent code // MapContent context = new MapContent(); villageLayer = new FeatureLayer(col, archStyle, "Khasra"); System.out.println("VILLAGELAYER"+villageLayer); context.addLayer(villageLayer); mapPane.setMapContent(context); Jan 22, 2013 2:49:31 PM org.geotools.map.MapContent getMaxBounds WARNING: Unable to determine bounds of org.geotools.map.FeatureLayer[Khasra, VISIBLE] java.lang.ClassCastException: java.lang.String cannot be cast to com.vividsolutions.jts.geom.Geometry at org.geotools.data.collection.CollectionDataStore.getBoundsInternal(CollectionDataStore.java:164) at org.geotools.data.collection.CollectionDataStore.getBounds(CollectionDataStore.java:145) at org.geotools.data.AbstractFeatureSource.getBounds(AbstractFeatureSource.java:318) at org.geotools.data.AbstractFeatureSource.getBounds(AbstractFeatureSource.java:286) at org.geotools.map.FeatureLayer.getBounds(FeatureLayer.java:195) at org.geotools.map.MapContent.getMaxBounds(MapContent.java:600) at org.geotools.map.MapContent.getViewport(MapContent.java:665) at org.geotools.swing.AbstractMapPane.doSetMapContent(AbstractMapPane.java:539) at org.geotools.swing.AbstractMapPane.setMapContent(AbstractMapPane.java:517) at org.geotools.swing.JMapPane.setMapContent(JMapPane.java:86) at in.nic.niccg.lrc.gis.lrcmapmutation.MapFactory.drawVillageMap(MapFactory.java:167) at in.nic.niccg.lrc.gis.lrcmapmutation.VillageMap$ShowMapTask.doInBackground(VillageMap.java:292) at org.jdesktop.swingworker.SwingWorker$1.call(Unknown Source) at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303) at java.util.concurrent.FutureTask.run(FutureTask.java:138) at org.jdesktop.swingworker.SwingWorker.run(Unknown Source) at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908) at java.lang.Thread.run(Thread.java:662) -- View this message in context: http://osgeo-org.1560.n6.nabble.com/Problem-in-showing-Layer-on-JmapPane-tp5028912.html Sent from the geotools-gt2-users mailing list archive at Nabble.com. |
From: Michael Bedward <michael.bedward@gm...> - 2013-01-22 10:33:45
|
Hello Kapil, Looking at the error trace, the problem is with your feature data ("java.lang.String cannot be cast to com.vividsolutions.jts.geom.Geometry"). Your FeatureHelper class must need a little help :) Michael On 22 January 2013 20:28, kapil <kapilsharma047@...> wrote: > Hi List, > > I want to show a map on JmapPane, but i found exception when i run the code. > Here is my code: > > ResultSet res = stmt.executeQuery(sql); > SimpleFeatureCollection col = > org.geotools.feature.FeatureCollections.newCollection(); > while (res.next()) { > > col.add(PolygonFeatureHelper.createPolyFeature(new > WKTReader().read(res.getString("the_geom")), res.getString("kide"))); > } > > StyleBuilder sb = new StyleBuilder(); > MapStyleSetings mapSty = new MapStyleSetings(); > //.............................. > Irrelevent code > // > MapContent context = new MapContent(); > > villageLayer = new FeatureLayer(col, archStyle, "Khasra"); > System.out.println("VILLAGELAYER"+villageLayer); > > > context.addLayer(villageLayer); > > > mapPane.setMapContent(context); > > > Jan 22, 2013 2:49:31 PM org.geotools.map.MapContent getMaxBounds > WARNING: Unable to determine bounds of org.geotools.map.FeatureLayer[Khasra, > VISIBLE] > java.lang.ClassCastException: java.lang.String cannot be cast to > com.vividsolutions.jts.geom.Geometry > at > org.geotools.data.collection.CollectionDataStore.getBoundsInternal(CollectionDataStore.java:164) > at > org.geotools.data.collection.CollectionDataStore.getBounds(CollectionDataStore.java:145) > at > org.geotools.data.AbstractFeatureSource.getBounds(AbstractFeatureSource.java:318) > at > org.geotools.data.AbstractFeatureSource.getBounds(AbstractFeatureSource.java:286) > at org.geotools.map.FeatureLayer.getBounds(FeatureLayer.java:195) > at org.geotools.map.MapContent.getMaxBounds(MapContent.java:600) > at org.geotools.map.MapContent.getViewport(MapContent.java:665) > at > org.geotools.swing.AbstractMapPane.doSetMapContent(AbstractMapPane.java:539) > at > org.geotools.swing.AbstractMapPane.setMapContent(AbstractMapPane.java:517) > at org.geotools.swing.JMapPane.setMapContent(JMapPane.java:86) > at > in.nic.niccg.lrc.gis.lrcmapmutation.MapFactory.drawVillageMap(MapFactory.java:167) > at > in.nic.niccg.lrc.gis.lrcmapmutation.VillageMap$ShowMapTask.doInBackground(VillageMap.java:292) > at org.jdesktop.swingworker.SwingWorker$1.call(Unknown Source) > at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303) > at java.util.concurrent.FutureTask.run(FutureTask.java:138) > at org.jdesktop.swingworker.SwingWorker.run(Unknown Source) > at > java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886) > at > java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908) > at java.lang.Thread.run(Thread.java:662) > > > > > -- > View this message in context: http://osgeo-org.1560.n6.nabble.com/Problem-in-showing-Layer-on-JmapPane-tp5028912.html > Sent from the geotools-gt2-users mailing list archive at Nabble.com. > > ------------------------------------------------------------------------------ > Master Visual Studio, SharePoint, SQL, ASP.NET, C# 2012, HTML5, CSS, > MVC, Windows 8 Apps, JavaScript and much more. Keep your skills current > with LearnDevNow - 3,200 step-by-step video tutorials by Microsoft > MVPs and experts. ON SALE this month only -- learn more at: > http://p.sf.net/sfu/learnnow-d2d > _______________________________________________ > GeoTools-GT2-Users mailing list > GeoTools-GT2-Users@... > https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users |
From: kapil <kapilsharma047@gm...> - 2013-01-23 06:56:13
|
Hi Michael, Thanks for helping me but i am still unable to solved out my problem in PolygonfeatureHelper class, I make a createPolygonFeature() which return SimpleFeature and this method call createFeatureType() Here is the code public static SimpleFeature createPolyFeature(Geometry geom, String name ) { GeometryFactory gf = new GeometryFactory(); if(geom instanceof Polygon ){ geom = new MultiPolygon(new Polygon[] {(Polygon)geom },new GeometryFactory()); } Object[] featureAttributes = { geom, name }; SimpleFeatureBuilder sfb = new SimpleFeatureBuilder(createFeatureType()); sfb.add(featureAttributes); SimpleFeature f = sfb.buildFeature(null); return f; } public static SimpleFeatureType createFeatureType() { AttributeDescriptor[] typesNew = new AttributeDescriptor[2]; AttributeTypeBuilder build = new AttributeTypeBuilder(); build.setBinding(String.class); build.setNillable(true); build.setLength(48); build.defaultValue(null); build.setName("NAME"); AttributeDescriptor descriptor = build.buildDescriptor( "NAME" ); AttributeTypeBuilder build1 = new AttributeTypeBuilder(); build1.setBinding(MultiPolygon.class); build1.setName("the_geom"); GeometryType geometryType = build1.buildGeometryType(); GeometryDescriptor geomdescriptor = build1.buildDescriptor( "the_geom", geometryType ); typesNew[0] = descriptor; typesNew[1] = geomdescriptor; SimpleFeatureTypeBuilder sf = new SimpleFeatureTypeBuilder(); sf.addAll(typesNew); sf.setName("Poly"); SimpleFeatureType ft = sf.buildFeatureType(); return ft; } -- View this message in context: http://osgeo-org.1560.n6.nabble.com/Problem-in-showing-Layer-on-JmapPane-tp5028912p5029151.html Sent from the geotools-gt2-users mailing list archive at Nabble.com. |
From: Michael Bedward <michael.bedward@gm...> - 2013-01-23 08:24:44
|
Hello Kapil, Your code is much more complicated that it needs to be and is also using very low-level classes / methods instead of higher-level user-friendly classes. Please study the GeoTools feature tutorial: http://docs.geotools.org/latest/userguide/tutorial/feature/csv2shp.html There you will see a better, easier way to create a SimpleFeatureType: http://docs.geotools.org/latest/userguide/tutorial/feature/csv2shp.html#another-way-to-build-a-simplefeaturetype Also, you should use GeometryFactory methods rather than creating geometries "by hand", e.g. to create a MultiPolygon object: http://tsusiatsoftware.net/jts/javadoc/com/vividsolutions/jts/geom/GeometryFactory.html#createMultiPolygon(com.vividsolutions.jts.geom.Polygon[]) Michael On 23 January 2013 17:56, kapil <kapilsharma047@...> wrote: > Hi Michael, > Thanks for helping me but i am still unable to solved out my problem in > PolygonfeatureHelper class, I make a createPolygonFeature() which return > SimpleFeature and this method call createFeatureType() > Here is the code > > > public static SimpleFeature createPolyFeature(Geometry geom, String name ) { > GeometryFactory gf = new GeometryFactory(); > > if(geom instanceof Polygon ){ > geom = new MultiPolygon(new Polygon[] {(Polygon)geom },new > GeometryFactory()); > } > Object[] featureAttributes = { geom, name }; > SimpleFeatureBuilder sfb = new > SimpleFeatureBuilder(createFeatureType()); > sfb.add(featureAttributes); > > SimpleFeature f = sfb.buildFeature(null); > return f; > } > public static SimpleFeatureType createFeatureType() { > > AttributeDescriptor[] typesNew = new AttributeDescriptor[2]; > AttributeTypeBuilder build = new AttributeTypeBuilder(); > build.setBinding(String.class); > build.setNillable(true); > build.setLength(48); > build.defaultValue(null); > build.setName("NAME"); > AttributeDescriptor descriptor = build.buildDescriptor( "NAME" ); > > AttributeTypeBuilder build1 = new AttributeTypeBuilder(); > build1.setBinding(MultiPolygon.class); > build1.setName("the_geom"); > GeometryType geometryType = build1.buildGeometryType(); > GeometryDescriptor geomdescriptor = build1.buildDescriptor( > "the_geom", geometryType ); > > typesNew[0] = descriptor; > typesNew[1] = geomdescriptor; > SimpleFeatureTypeBuilder sf = new SimpleFeatureTypeBuilder(); > sf.addAll(typesNew); > sf.setName("Poly"); > > SimpleFeatureType ft = sf.buildFeatureType(); > return ft; > } > > > > > -- > View this message in context: http://osgeo-org.1560.n6.nabble.com/Problem-in-showing-Layer-on-JmapPane-tp5028912p5029151.html > Sent from the geotools-gt2-users mailing list archive at Nabble.com. > > ------------------------------------------------------------------------------ > Master Visual Studio, SharePoint, SQL, ASP.NET, C# 2012, HTML5, CSS, > MVC, Windows 8 Apps, JavaScript and much more. Keep your skills current > with LearnDevNow - 3,200 step-by-step video tutorials by Microsoft > MVPs and experts. ON SALE this month only -- learn more at: > http://p.sf.net/sfu/learnnow-d2d > _______________________________________________ > GeoTools-GT2-Users mailing list > GeoTools-GT2-Users@... > https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users |