Nov 22
displaying shapefiles in wwjava
here is a quick hack to add esri shapefiles support in worlwind java:
1- get gistoolkit
2- strip de bones (keep only gistoolkit.features.*, gistoolkit.common and gistoolkit.datasources.shapefile)
3 - Link to your project.
4- then you can add a shapefile to a layer by doing something like this, if you are really lazy:
ShapeFile shp = new ShapeFile(fn); if (shp == null) return; try { shp.readRecords(); } catch(Exception e) { err("Error while reading shape."); return; } ShapeFileRecord[] r = shp.getRecords(); int i, j; fireLayer.clearList(); gistoolkit.features.Point lastCenter = null; for(i=0; i<r.length; i++) { gistoolkit.features.Shape s = r[i].getShape(); if (s.getShapeType() == "MULTIPOLYGON") { gistoolkit.features.MultiPolygon m = (gistoolkit.features.MultiPolygon) s; gistoolkit.features.Polygon[] polys = m.getPolygons(); for(j=0; j<polys.length; j++) { addPolygon(polys[j]); lastCenter = polys[j].getCentroid(); } } } private void addPolygon(gistoolkit.features.Polygon p) { int i; ArrayList<LatLon> positions = new ArrayList<LatLon>(); gistoolkit.features.Point[] pts = p.getPoints(); for(i=0; i<pts.length; i++) { positions.add(LatLon.fromDegrees(pts[i].y, pts[i].x)); } Dimension texSize = new Dimension(); texSize.setSize(1024, 1024); SurfacePolygon fire = new SurfacePolygon(positions, new Color(1f, 0f, 0f), new Color(1f, 0f, 0f), texSize); fire.setDrawInterior(true); fireLayer.addRenderable(fire); }
fireLayer is a RenderableLayer that was initialized previously.
texSize is needed so that the shape doesn’t look too blurry.








February 11th, 2008 at 7:44 am
That’s great, i Created polygon layer with only one feature (3 points) and it works, but if I add my data (polygon with 7 features and each polygon has 10-300 points) WWWJ hangs, also drag will not work if you click on the layer to move the map, but if you click on other area it works.
February 11th, 2008 at 8:31 am
Performances are not too bad over here with polygons with 3-200 points but you could either generate the shapefile in a thread or use the Douglas-Peucker polygon reduction algorithm.
I have the same problem with the drag, let me know if you find any solutions.
February 14th, 2008 at 8:29 pm
fireLayer.setPickEnabled(false); will solve the drag problem