1

I have polygon geometries that represent building footprints in a shapefile and I want to extrude them according to an attribute "height" and turn them 3B objects as polyhedral surfaces via extrusion. For this purpose I am writing an extrusion function. I am using geotools to access and extract geometries and attributes from shapefile. I am creating top and bottom faces of buildings as polygon geometries but I could not generate vertical faces. I could not write a loop that traverse positions and create vertical faces as polygon geometries. I am stuck with it.

Here is the rest of my code after I extract polygons ;

List<Polygon> polygons = bb.getBboxFeature(shapeFilePath);

List<PolyhedralSurface> mesh = new ArrayList<PolyhedralSurface>();

for(Polygon poly : polygons) {

    Coordinate[] coords = poly.getCoordinates();
    List<Polygon> faces = new ArrayList<Polygon>();

    for (int i =0; i<coords.length; i++) {

        Double h = 15.00;
        GeometryBuilder builder = new GeometryBuilder(DefaultGeographicCRS.WGS84_3D);
        List<Position> dpsBottom = new ArrayList<Position>();
        List<Position> dpsTop = new ArrayList<Position>();

        //bottom positions created using coordinates

        dpsBottom.add(builder.createDirectPosition(new double[] {coords[i].x, coords[i].y, 0}));

        //top positions created using coordinates

        dpsTop.add(builder.createDirectPosition(new double[] {coords[i].x, coords[i].y, h}));

My final purpose is create vertical faces and add them to a polygon list. Then, finaly giving this list to createPolyhedralSurface() function as input and create building as polyhedral geometry.

Is there a more efficient solution for my purpose?

1 Answer 1

1

In principal, this code should do what you want:

public PolyhedralSurface extrudePolygon(Polygon poly, double h) {
    Coordinate[] polyPoints = poly.getBoundary().getCoordinates();
    List<org.opengis.geometry.coordinate.Polygon> faces = new ArrayList<>();

    for (int i = 1; i < poly.getNumPoints(); i++) {
      double[] coords = new double[15];
      coords[0] = polyPoints[i - 1].x;
      coords[1] = polyPoints[i - 1].y;
      coords[2] = 0;
      coords[3] = polyPoints[i].x;
      coords[4] = polyPoints[i].y;
      coords[5] = 0;
      coords[6] = polyPoints[i].x;
      coords[7] = polyPoints[i].y;
      coords[8] = h;
      coords[9] = polyPoints[i - 1].x;
      coords[10] = polyPoints[i - 1].y;
      coords[11] = h;
      coords[12] = polyPoints[i - 1].x;
      coords[13] = polyPoints[i - 1].y;
      coords[14] = 0;
      PointArray points = builder.createPointArray(coords);
      // for each edge create a polygon
      SurfaceBoundary surfaceBoundary = builder.createSurfaceBoundary(points);
      org.opengis.geometry.coordinate.Polygon face = builder.createPolygon(surfaceBoundary);
      faces.add(face);
    }
    faces.add(poly);
    //add top face too
    return builder.createPolyhedralSurface(faces);
  }

But, this fails because the Geometry validation code seems to only work in two dimensions so it thinks the face polygons intersect. You can skip this test by adding:

hints.put(Hints.GEOMETRY_VALIDATE, false);

But then you get to the real problem, org.geotools.geometry.iso.coordinate.GeometryFactoryImpl.createPolyhedralSurface is not implemented (yet).

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.