// Its FShape and not FPolygon2D because FPolygon2DM returns a FPolyline private FShape parseMultiPolygon(ByteBuffer data) { // it was expected not to find polygons with different srid or // coordiante dimension as subelements of the multipolygon // PostGIS avoid this behaviour, but OGC says it is allow. int count = data.getInt(); GeneralPathX gp = new GeneralPathX(); List<Double> d3 = null; int nDims = 2; if (gHaveZ || gHaveM) nDims = 3; if (nDims == 3) d3 = new ArrayList<Double>(); for (int i = 0; i < count; i++) { parseTypeAndSRID(data); int countRings = data.getInt(); for (int j = 0; j < countRings; j++) { FPoint2D[] points = parsePointArray(data, gHaveZ, gHaveM); for (int k = 0; k < points.length; k++) { if (k == points.length - 1) { gp.closePath(); if (nDims == 3) { if (gHaveZ) d3.add(((FPoint3D) points[0]).getZ()); else if (gHaveM) d3.add(((FPoint2DM) points[0]).getM()); else d3.add(0.0); // child does not have 3 dimensions } } else { // parent has 3 dimensions if (nDims == 3) { if (gHaveZ) d3.add(((FPoint3D) points[k]).getZ()); else if (gHaveM) d3.add(((FPoint2DM) points[k]).getM()); else d3.add(0.0); // child does not have 3 dimensions } if (k == 0) gp.moveTo(points[k].getX(), points[k].getY()); else gp.lineTo(points[k].getX(), points[k].getY()); } } } } if (nDims == 3) { double ad3[] = new double[d3.size()]; for (int i = 0; i < d3.size(); i++) { ad3[i] = ((Double) d3.get(i)).doubleValue(); } if (gHaveZ) return new FPolygon3D(gp, ad3); else return new FPolygon2DM(gp, ad3); } return new FPolygon2D(gp); }
private FShape parsePolygon(ByteBuffer data, boolean haveZ, boolean haveM) { GeneralPathX gp = new GeneralPathX(); List<Double> d3 = null; int nDims = 2; if (gHaveZ || gHaveM) nDims = 3; if (nDims == 3) d3 = new ArrayList<Double>(); int countRings = data.getInt(); for (int j = 0; j < countRings; j++) { FPoint2D[] points = parsePointArray(data, gHaveZ, gHaveM); for (int k = 0; k < points.length; k++) { if (k == points.length - 1) { gp.closePath(); if (nDims == 3) { if (gHaveZ) d3.add(((FPoint3D) points[0]).getZ()); else if (gHaveM) d3.add(((FPoint2DM) points[0]).getM()); else d3.add(0.0); // child does not have 3 dimensions } } else { // parent has 3 dimensions if (nDims == 3) { if (gHaveZ) d3.add(((FPoint3D) points[k]).getZ()); else if (gHaveM) d3.add(((FPoint2DM) points[k]).getM()); else d3.add(0.0); // child does not have 3 dimensions } if (k == 0) gp.moveTo(points[k].getX(), points[k].getY()); else gp.lineTo(points[k].getX(), points[k].getY()); } } } if (nDims == 3) { double ad3[] = new double[d3.size()]; for (int i = 0; i < d3.size(); i++) { ad3[i] = ((Double) d3.get(i)).doubleValue(); } if (gHaveZ) return new FPolygon3D(gp, ad3); else return new FPolygon2DM(gp, ad3); } return new FPolygon2D(gp); }