Search in sources :

Example 41 with Polygon

use of com.vividsolutions.jts.geom.Polygon in project ili2db by claeis.

the class Fgdb2iox method readGeometry.

private IomObject readGeometry() throws IOException, ParseException, IoxException {
    dis.setOrder(ByteOrderValues.LITTLE_ENDIAN);
    int typeInt = dis.readInt();
    int geometryType = typeInt & EsriShpConstants.shapeBasicTypeMask;
    if (geometryType == EsriShpConstants.ShapeNull) {
        return null;
    }
    // determine if Z values are present
    hasZ = geometryType == EsriShpConstants.ShapePointZM || geometryType == EsriShpConstants.ShapePointZ || geometryType == EsriShpConstants.ShapeMultiPointZM || geometryType == EsriShpConstants.ShapeMultiPointZ || geometryType == EsriShpConstants.ShapePolylineZM || geometryType == EsriShpConstants.ShapePolylineZ || geometryType == EsriShpConstants.ShapePolygonZM || geometryType == EsriShpConstants.ShapePolygonZ || (geometryType == EsriShpConstants.ShapeGeneralPoint || geometryType == EsriShpConstants.ShapeGeneralPolyline || geometryType == EsriShpConstants.ShapeGeneralPolygon || geometryType == EsriShpConstants.ShapeGeneralMultiPoint || geometryType == EsriShpConstants.ShapeGeneralMultiPatch) && ((typeInt & EsriShpConstants.shapeHasZs) != 0);
    boolean hasM = geometryType == EsriShpConstants.ShapePointZM || geometryType == EsriShpConstants.ShapePointM || geometryType == EsriShpConstants.ShapeMultiPointZM || geometryType == EsriShpConstants.ShapeMultiPointM || geometryType == EsriShpConstants.ShapePolylineZM || geometryType == EsriShpConstants.ShapePolylineM || geometryType == EsriShpConstants.ShapePolygonZM || geometryType == EsriShpConstants.ShapePolygonM || (geometryType == EsriShpConstants.ShapeGeneralPoint || geometryType == EsriShpConstants.ShapeGeneralPolyline || geometryType == EsriShpConstants.ShapeGeneralPolygon || geometryType == EsriShpConstants.ShapeGeneralMultiPoint || geometryType == EsriShpConstants.ShapeGeneralMultiPatch) && ((typeInt & EsriShpConstants.shapeHasMs) != 0);
    boolean hasCurves = (geometryType == EsriShpConstants.ShapeGeneralPolyline || geometryType == EsriShpConstants.ShapeGeneralPolygon) && (typeInt & EsriShpConstants.shapeNonBasicModifierMask) != 0 || (typeInt & EsriShpConstants.shapeHasCurves) != 0;
    inputDimension = hasZ ? 3 : 2;
    // only allocate ordValues buffer if necessary
    if (ordValues == null || ordValues.length < inputDimension)
        ordValues = new double[inputDimension];
    if (geometryType == EsriShpConstants.ShapePoint || geometryType == EsriShpConstants.ShapePointZM || geometryType == EsriShpConstants.ShapePointZ || geometryType == EsriShpConstants.ShapeGeneralPoint) {
        double x = dis.readDouble();
        double y = dis.readDouble();
        IomObject ret = new ch.interlis.iom_j.Iom_jObject("COORD", null);
        ret.setattrvalue("C1", Double.toString(x));
        ret.setattrvalue("C2", Double.toString(y));
        if (hasZ) {
            double z = dis.readDouble();
            ret.setattrvalue("C3", Double.toString(z));
        }
        return ret;
    }
    if (geometryType == EsriShpConstants.ShapeGeneralMultiPatch) {
        throw new IoxException("unexpected geometryType " + geometryType);
    }
    // boundingBox
    double min_x = dis.readDouble();
    double min_y = dis.readDouble();
    double max_x = dis.readDouble();
    double max_y = dis.readDouble();
    // cParts
    int cParts = 0;
    int[] partStart = null;
    if (geometryType == EsriShpConstants.ShapeMultiPoint || geometryType == EsriShpConstants.ShapeMultiPointZM || geometryType == EsriShpConstants.ShapeMultiPointZ || geometryType == EsriShpConstants.ShapeGeneralMultiPoint) {
    } else {
        cParts = dis.readInt();
        partStart = new int[cParts];
    }
    // cPoints
    int cPoints = dis.readInt();
    // parts[cParts]
    if (cParts > 0) {
        for (int i = 0; i < cParts; i++) {
            partStart[i] = dis.readInt();
        }
    }
    // points[cPoints]
    Coordinate[] points = new Coordinate[cPoints];
    for (int i = 0; i < cPoints; i++) {
        points[i] = new Coordinate();
        points[i].x = dis.readDouble();
        points[i].y = dis.readDouble();
    }
    if (geometryType == EsriShpConstants.ShapeMultiPoint || geometryType == EsriShpConstants.ShapeMultiPointZM || geometryType == EsriShpConstants.ShapeMultiPointZ || geometryType == EsriShpConstants.ShapeGeneralMultiPoint) {
        throw new IoxException("unexpected geometryType " + geometryType);
    } else if (geometryType == EsriShpConstants.ShapePolyline || geometryType == EsriShpConstants.ShapePolylineZM || geometryType == EsriShpConstants.ShapePolylineZ || geometryType == EsriShpConstants.ShapeGeneralPolyline) {
    } else if (geometryType == EsriShpConstants.ShapePolygon || geometryType == EsriShpConstants.ShapePolygonZM || geometryType == EsriShpConstants.ShapePolygonZ || geometryType == EsriShpConstants.ShapeGeneralPolygon) {
    } else {
        throw new IoxException("unexpected geometryType " + geometryType);
    }
    if (hasZ) {
        double min_z = dis.readDouble();
        double max_z = dis.readDouble();
        // Zs[cPoints]
        for (int i = 0; i < cPoints; i++) {
            points[i].z = dis.readDouble();
        }
    }
    if (hasM) {
        double min_m = dis.readDouble();
        double max_m = dis.readDouble();
        // Ms[cPoints]
        for (int i = 0; i < cPoints; i++) {
            // ignore
            dis.readDouble();
        }
    }
    java.util.Map<Integer, Arc> arcs = null;
    if (hasCurves) {
        int cSegmentModifiers = dis.readInt();
        arcs = new java.util.HashMap<Integer, Arc>();
        for (int i = 0; i < cSegmentModifiers; i++) {
            int startPointIndex = dis.readInt();
            int segmentType = dis.readInt();
            if (segmentType == EsriShpConstants.segmentArc) {
                double v1 = dis.readDouble();
                double v2 = dis.readDouble();
                int bits = dis.readInt();
                // int skip1=dis.readInt();
                if ((bits & EsriShpConstants.arcIsEmpty) != 0) {
                // skip it
                } else if ((bits & EsriShpConstants.arcIsLine) != 0) {
                // straight line, skip it
                } else if ((bits & EsriShpConstants.arcIsPoint) != 0) {
                    throw new IoxException("not supported SegmentArc.Bits " + bits);
                } else if ((bits & EsriShpConstants.arcDefinedIP) != 0) {
                // throw new IoxException("not supported SegmentArc.Bits "+bits);
                } else {
                    if ((bits & EsriShpConstants.arcIsCCW) != 0) {
                    // counterclockwise
                    } else {
                    // clockwise
                    }
                }
                // double skip1=dis.readDouble();
                // double skip2=dis.readDouble();
                // double skip3=dis.readDouble();
                arcs.put(startPointIndex, new Arc(startPointIndex, v1, v2, bits));
            } else if (segmentType == EsriShpConstants.segmentLine) {
            // will never appear; should be ignored
            } else if (segmentType == EsriShpConstants.segmentSpiral) {
            } else if (segmentType == EsriShpConstants.segmentBezier3Curve) {
                // two middle control points
                double skip1 = dis.readDouble();
                double skip2 = dis.readDouble();
                double skip3 = dis.readDouble();
                double skip4 = dis.readDouble();
            } else if (segmentType == EsriShpConstants.segmentEllipticArc) {
                // center
                double skip1 = dis.readDouble();
                double skip2 = dis.readDouble();
                // rotation or fromV
                double skip3 = dis.readDouble();
                // semiMajor
                double skip4 = dis.readDouble();
                // minorMajorRatio or deltaV
                double skip5 = dis.readDouble();
                // bits
                int skip6 = dis.readInt();
            } else if (segmentType == 0) {
                break;
            } else {
                throw new IoxException("unexpected segmentType " + segmentType);
            // EhiLogger.traceState(("unexpected segmentType "+segmentType));
            // continue;
            }
        }
    }
    JtsextGeometryFactory fact = new JtsextGeometryFactory();
    if (geometryType == EsriShpConstants.ShapePolyline || geometryType == EsriShpConstants.ShapePolylineZM || geometryType == EsriShpConstants.ShapePolylineZ || geometryType == EsriShpConstants.ShapeGeneralPolyline) {
        if (cParts == 1) {
            LineString line = getPolyline(fact, 0, points, partStart, arcs, false);
            IomObject ret;
            try {
                ret = Jtsext2iox.JTS2polyline(line);
            } catch (Iox2jtsException e) {
                throw new IoxException(e);
            }
            return ret;
        }
        IomObject ret = new Iom_jObject(Wkb2iox.OBJ_MULTIPOLYLINE, null);
        for (int i = 0; i < cParts; i++) {
            LineString line = getPolyline(fact, i, points, partStart, arcs, false);
            try {
                IomObject lineObj = Jtsext2iox.JTS2polyline(line);
                ret.addattrobj(Wkb2iox.ATTR_POLYLINE, lineObj);
            } catch (Iox2jtsException e) {
                throw new IoxException(e);
            }
        }
        return ret;
    } else if (geometryType == EsriShpConstants.ShapePolygon || geometryType == EsriShpConstants.ShapePolygonZM || geometryType == EsriShpConstants.ShapePolygonZ || geometryType == EsriShpConstants.ShapeGeneralPolygon) {
        if (cParts == 1) {
            LineString line = getPolyline(fact, 0, points, partStart, arcs, true);
            if (line.getCoordinateSequence().size() <= 3) {
                throw new IoxException("Not a Ring");
            }
            Polygon polygon = fact.createCurvePolygon(fact.createRing(line));
            IomObject ret;
            try {
                ret = Jtsext2iox.JTS2surface(polygon);
            } catch (Iox2jtsException e) {
                throw new IoxException(e);
            }
            return ret;
        }
        ArrayList<LineString> shells = new ArrayList<LineString>();
        ArrayList<LineString> holes = new ArrayList<LineString>();
        for (int i = 0; i < cParts; i++) {
            LineString line = getPolyline(fact, i, points, partStart, arcs, true);
            if (line.getCoordinateSequence().size() <= 3) {
                throw new IoxException("Not a Ring");
            }
            if (CGAlgorithms.isCCW(line.getCoordinates())) {
                holes.add(line);
            } else {
                shells.add(line);
            }
        }
        if (shells.size() == 0) {
            throw new IoxException("polygon without shell");
        } else if (shells.size() == 1) {
            LinearRing shell = fact.createRing(shells.get(0));
            Polygon polygon = null;
            if (holes.size() == 0) {
                polygon = fact.createPolygon(shell);
            } else {
                LinearRing[] hole = new LinearRing[holes.size()];
                int i = 0;
                for (LineString line : holes) {
                    hole[i] = fact.createRing(line);
                    i++;
                }
                polygon = fact.createPolygon(shell, hole);
            }
            IomObject ret = null;
            try {
                ret = Jtsext2iox.JTS2surface(polygon);
            } catch (Iox2jtsException e) {
                throw new IoxException(e);
            }
            return ret;
        } else {
        // TODO  MultiSurface
        }
        return null;
    } else {
        throw new IoxException("unexpected geometryType " + geometryType);
    }
}
Also used : ArrayList(java.util.ArrayList) Iom_jObject(ch.interlis.iom_j.Iom_jObject) IomObject(ch.interlis.iom.IomObject) Coordinate(com.vividsolutions.jts.geom.Coordinate) LineString(com.vividsolutions.jts.geom.LineString) JtsextGeometryFactory(ch.interlis.iom_j.itf.impl.jtsext.geom.JtsextGeometryFactory) CurvePolygon(ch.interlis.iom_j.itf.impl.jtsext.geom.CurvePolygon) Polygon(com.vividsolutions.jts.geom.Polygon) LinearRing(com.vividsolutions.jts.geom.LinearRing) IoxException(ch.interlis.iox.IoxException) Iox2jtsException(ch.interlis.iox_j.jts.Iox2jtsException)

Example 42 with Polygon

use of com.vividsolutions.jts.geom.Polygon in project ili2db by claeis.

the class Iox2fgdb method surface2wkb.

/**
 * Converts a SURFACE to a JTS Polygon.
 * @param obj INTERLIS SURFACE structure
 * @param strokeP maximum stroke to use when removing ARCs
 * @return JTS Polygon
 * @throws Iox2wkbException
 */
public byte[] surface2wkb(// SurfaceOrAreaType type)
IomObject polygonObj, // SurfaceOrAreaType type)
boolean asCurvePolygon, // SurfaceOrAreaType type)
double strokeP, // SurfaceOrAreaType type)
int srsId) throws IoxException {
    if (polygonObj == null) {
        return null;
    }
    byte[] ret = null;
    Polygon polygon = Iox2jtsext.surface2JTS(polygonObj, strokeP);
    os.reset();
    if (asCurvePolygon) {
        int shapeType = EsriShpConstants.ShapeGeneralPolygon;
        shapeType |= EsriShpConstants.shapeHasCurves;
        shapeType |= (outputDimension == 3 ? EsriShpConstants.shapeHasZs : 0);
        os.writeInt(shapeType);
    } else {
        if (outputDimension == 3) {
            os.writeInt(EsriShpConstants.ShapePolygonZ);
        } else {
            os.writeInt(EsriShpConstants.ShapePolygon);
        }
    }
    // boundingBox
    Envelope env = polygon.getEnvelopeInternal();
    os.writeDouble(env.getMinX());
    os.writeDouble(env.getMinY());
    os.writeDouble(env.getMaxX());
    os.writeDouble(env.getMaxY());
    // cParts The number of rings in the polygon.
    // cPoints The total number of points for all parts.
    int cPart = 1;
    int cPoints = getNumPoints(polygon.getExteriorRing());
    int holec = polygon.getNumInteriorRing();
    cPart += holec;
    for (int holei = 0; holei < holec; holei++) {
        cPoints += getNumPoints(polygon.getInteriorRingN(holei));
    }
    os.writeInt(cPart);
    os.writeInt(cPoints);
    // parts[cParts] An array of length NumParts. Stores, for each Ring, the index of its
    // first point in the points array. Array indexes are with respect to 0.
    int partStart = 0;
    os.writeInt(partStart);
    partStart += getNumPoints(polygon.getExteriorRing());
    for (int holei = 0; holei < holec; holei++) {
        os.writeInt(partStart);
        partStart += getNumPoints(polygon.getInteriorRingN(holei));
    }
    java.util.ArrayList<Arc> arcs = null;
    if (asCurvePolygon) {
        arcs = new java.util.ArrayList<Arc>();
    }
    java.util.ArrayList<Double> zv = null;
    if (outputDimension == 3) {
        zv = new java.util.ArrayList<Double>();
    }
    double[] zMin = new double[1];
    double[] zMax = new double[1];
    {
        Coordinate coord = polygon.getExteriorRing().getStartPoint().getCoordinate();
        if (outputDimension == 3) {
            zMin[0] = coord.z;
            zMax[0] = coord.z;
        }
    }
    // shell is always in clockwise order
    // holes are in a counterclockwise direction
    LineString polyline = polygon.getExteriorRing();
    int startPtIdx = 0;
    polyline = asOneLine(polyline);
    if (CGAlgorithms.isCCW(polyline.getCoordinates())) {
        polyline = (LineString) polyline.reverse();
    }
    writePoints(polyline, false, zv, zMin, zMax, startPtIdx, arcs);
    startPtIdx += getNumPoints(polyline);
    for (int holei = 0; holei < holec; holei++) {
        polyline = polygon.getInteriorRingN(holei);
        polyline = asOneLine(polyline);
        if (!CGAlgorithms.isCCW(polyline.getCoordinates())) {
            polyline = (LineString) polyline.reverse();
        }
        writePoints(polyline, true, zv, zMin, zMax, startPtIdx, arcs);
        startPtIdx += getNumPoints(polyline);
    }
    if (outputDimension == 3) {
        // zMin
        os.writeDouble(zMin[0]);
        // zMax
        os.writeDouble(zMax[0]);
        // Zs[cPoints]
        for (Double z : zv) {
            os.writeDouble(z);
        }
    }
    if (asCurvePolygon) {
        writeArcs(arcs);
    }
    ret = os.toByteArray();
    return ret;
}
Also used : Coordinate(com.vividsolutions.jts.geom.Coordinate) LineString(com.vividsolutions.jts.geom.LineString) Polygon(com.vividsolutions.jts.geom.Polygon) Envelope(com.vividsolutions.jts.geom.Envelope)

Example 43 with Polygon

use of com.vividsolutions.jts.geom.Polygon in project ili2db by claeis.

the class Iox2fgdb method multisurface2wkb.

public byte[] multisurface2wkb(// SurfaceOrAreaType type)
IomObject multisurfaceObj, // SurfaceOrAreaType type)
boolean asCurvePolygon, // SurfaceOrAreaType type)
double strokeP, // SurfaceOrAreaType type)
int srsId) throws IoxException {
    if (multisurfaceObj == null) {
        return null;
    }
    byte[] ret = null;
    os.reset();
    if (asCurvePolygon) {
        int shapeType = EsriShpConstants.ShapeGeneralPolygon;
        shapeType |= EsriShpConstants.shapeHasCurves;
        shapeType |= (outputDimension == 3 ? EsriShpConstants.shapeHasZs : 0);
        os.writeInt(shapeType);
    } else {
        if (outputDimension == 3) {
            os.writeInt(EsriShpConstants.ShapePolygonZ);
        } else {
            os.writeInt(EsriShpConstants.ShapePolygon);
        }
    }
    java.util.ArrayList<Polygon> polygons = new java.util.ArrayList<Polygon>();
    // boundingBox
    Envelope env = new Envelope();
    int surfacec = multisurfaceObj.getattrvaluecount("surface");
    for (int surfacei = 0; surfacei < surfacec; surfacei++) {
        IomObject surface = multisurfaceObj.getattrobj("surface", surfacei);
        IomObject iomSurfaceClone = new ch.interlis.iom_j.Iom_jObject("MULTISURFACE", null);
        iomSurfaceClone.addattrobj("surface", surface);
        Polygon polygon = Iox2jtsext.surface2JTS(iomSurfaceClone, strokeP);
        polygons.add(polygon);
        env.expandToInclude(polygon.getEnvelopeInternal());
    }
    os.writeDouble(env.getMinX());
    os.writeDouble(env.getMinY());
    os.writeDouble(env.getMaxX());
    os.writeDouble(env.getMaxY());
    // cParts The number of rings in the multisurface.
    // cPoints The total number of points for all parts.
    int cPart = 0;
    int cPoints = 0;
    for (Polygon polygon : polygons) {
        cPart += 1;
        cPoints += getNumPoints(polygon.getExteriorRing());
        int holec = polygon.getNumInteriorRing();
        cPart += holec;
        for (int holei = 0; holei < holec; holei++) {
            cPoints += getNumPoints(polygon.getInteriorRingN(holei));
        }
    }
    os.writeInt(cPart);
    os.writeInt(cPoints);
    // parts[cParts] An array of length NumParts. Stores, for each Ring, the index of its
    // first point in the points array. Array indexes are with respect to 0.
    int partStart = 0;
    for (Polygon polygon : polygons) {
        os.writeInt(partStart);
        partStart += getNumPoints(polygon.getExteriorRing());
        int holec = polygon.getNumInteriorRing();
        for (int holei = 0; holei < holec; holei++) {
            os.writeInt(partStart);
            partStart += getNumPoints(polygon.getInteriorRingN(holei));
        }
    }
    java.util.ArrayList<Arc> arcs = null;
    if (asCurvePolygon) {
        arcs = new java.util.ArrayList<Arc>();
    }
    java.util.ArrayList<Double> zv = null;
    if (outputDimension == 3) {
        zv = new java.util.ArrayList<Double>();
    }
    double[] zMin = new double[1];
    double[] zMax = new double[1];
    {
        Coordinate coord = polygons.get(0).getExteriorRing().getStartPoint().getCoordinate();
        if (outputDimension == 3) {
            zMin[0] = coord.z;
            zMax[0] = coord.z;
        }
    }
    int startPtIdx = 0;
    for (Polygon polygon : polygons) {
        // shell is always in clockwise order
        // holes are in a counterclockwise direction
        LineString polyline = polygon.getExteriorRing();
        polyline = asOneLine(polyline);
        if (CGAlgorithms.isCCW(polyline.getCoordinates())) {
            polyline = (LineString) polyline.reverse();
        }
        writePoints(polyline, false, zv, zMin, zMax, startPtIdx, arcs);
        startPtIdx += getNumPoints(polyline);
        int holec = polygon.getNumInteriorRing();
        for (int holei = 0; holei < holec; holei++) {
            polyline = polygon.getInteriorRingN(holei);
            polyline = asOneLine(polyline);
            if (!CGAlgorithms.isCCW(polyline.getCoordinates())) {
                polyline = (LineString) polyline.reverse();
            }
            writePoints(polyline, true, zv, zMin, zMax, startPtIdx, arcs);
            startPtIdx += getNumPoints(polyline);
        }
    }
    if (outputDimension == 3) {
        // zMin
        os.writeDouble(zMin[0]);
        // zMax
        os.writeDouble(zMax[0]);
        // Zs[cPoints]
        for (Double z : zv) {
            os.writeDouble(z);
        }
    }
    if (asCurvePolygon) {
        writeArcs(arcs);
    }
    ret = os.toByteArray();
    return ret;
}
Also used : ArrayList(java.util.ArrayList) Envelope(com.vividsolutions.jts.geom.Envelope) IomObject(ch.interlis.iom.IomObject) Coordinate(com.vividsolutions.jts.geom.Coordinate) LineString(com.vividsolutions.jts.geom.LineString) Polygon(com.vividsolutions.jts.geom.Polygon)

Example 44 with Polygon

use of com.vividsolutions.jts.geom.Polygon in project ili2db by claeis.

the class Iox2gpkg method surface2wkb.

/**
 * Converts a SURFACE to a JTS Polygon.
 * @param obj INTERLIS SURFACE structure
 * @param strokeP maximum stroke to use when removing ARCs
 * @return JTS Polygon
 * @throws Iox2wkbException
 */
public byte[] surface2wkb(// SurfaceOrAreaType type)
IomObject obj, // SurfaceOrAreaType type)
boolean asCurvePolygon, // SurfaceOrAreaType type)
double strokeP, // SurfaceOrAreaType type)
int srsId) throws Iox2wkbException {
    if (obj == null) {
        return null;
    }
    try {
        os.reset();
        Polygon surface = Iox2jtsext.surface2JTS(obj, strokeP);
        writeGeoPackageBinaryHeader(srsId, surface.getEnvelopeInternal());
        // wkb
        Iox2wkb helper = new Iox2wkb(outputDimension, os.order());
        os.write(helper.surface2wkb(obj, asCurvePolygon, strokeP));
    } catch (IOException e) {
        throw new RuntimeException("Unexpected IO exception: " + e.getMessage());
    } catch (IoxException e) {
        throw new RuntimeException("Unexpected exception: " + e.getMessage());
    }
    return os.toByteArray();
}
Also used : Iox2wkb(ch.interlis.iox_j.wkb.Iox2wkb) IOException(java.io.IOException) Polygon(com.vividsolutions.jts.geom.Polygon) IoxException(ch.interlis.iox.IoxException)

Example 45 with Polygon

use of com.vividsolutions.jts.geom.Polygon in project tests by datanucleus.

the class JtsGeometrySpatialTest method testDifference.

@Datastore(POSTGRESQL)
public void testDifference() throws SQLException, ParseException {
    PersistenceManager pm = pmf.getPersistenceManager();
    Transaction tx = pm.currentTransaction();
    try {
        tx.begin();
        Polygon polygon = (Polygon) wktReader.read("POLYGON((75 75,100 75,100 80,80 80,75 75))");
        Polygon difference = (Polygon) wktReader.read("POLYGON((80 80,100 100,100 80,80 80))");
        Query query = pm.newQuery(SamplePolygon.class, "geom != null && geom.difference(:polygon).equals(:difference)");
        List list = (List) query.execute(polygon, difference);
        assertEquals("Wrong number of geometries whose difference from a given polygon is equal to a given polygon returned", 1, list.size());
        assertTrue("Polygon 2 should be in the list of geometries whose difference from a given polygon is equal to a given polygon", list.contains(getSamplePolygon(2)));
        query = pm.newQuery(SamplePolygon.class, "id == :id");
        query.setResult("geom.difference(Spatial.geomFromText('POLYGON((75 75,100 75,100 80,80 80,75 75))', 4326))");
        query.setUnique(true);
        Geometry difference_read = (Geometry) query.execute(new Long(getSamplePolygon(2).getId()));
        difference.normalize();
        difference_read.normalize();
        assertTrue("Returned difference should be equal to the given polygon", difference_read.equalsExact(difference));
    } finally {
        tx.commit();
    }
}
Also used : Geometry(com.vividsolutions.jts.geom.Geometry) Transaction(javax.jdo.Transaction) Query(javax.jdo.Query) PersistenceManager(javax.jdo.PersistenceManager) SamplePolygon(org.datanucleus.samples.jtsgeometry.SamplePolygon) List(java.util.List) MultiPolygon(com.vividsolutions.jts.geom.MultiPolygon) SamplePolygon(org.datanucleus.samples.jtsgeometry.SamplePolygon) Polygon(com.vividsolutions.jts.geom.Polygon) Datastore(org.datanucleus.tests.annotations.Datastore)

Aggregations

Polygon (com.vividsolutions.jts.geom.Polygon)112 LinearRing (com.vividsolutions.jts.geom.LinearRing)51 MultiPolygon (com.vividsolutions.jts.geom.MultiPolygon)34 Test (org.junit.Test)32 Coordinate (com.vividsolutions.jts.geom.Coordinate)30 Point (com.vividsolutions.jts.geom.Point)27 PackedCoordinateSequence (com.vividsolutions.jts.geom.impl.PackedCoordinateSequence)27 ArrayList (java.util.ArrayList)26 RdfToRyaConversions.convertStatement (org.apache.rya.api.resolver.RdfToRyaConversions.convertStatement)24 Resource (org.openrdf.model.Resource)24 Statement (org.openrdf.model.Statement)24 URI (org.openrdf.model.URI)24 Value (org.openrdf.model.Value)24 ValueFactory (org.openrdf.model.ValueFactory)24 ContextStatementImpl (org.openrdf.model.impl.ContextStatementImpl)24 ValueFactoryImpl (org.openrdf.model.impl.ValueFactoryImpl)24 Geometry (com.vividsolutions.jts.geom.Geometry)22 LineString (com.vividsolutions.jts.geom.LineString)22 List (java.util.List)20 PersistenceManager (javax.jdo.PersistenceManager)15