Java 类com.vividsolutions.jts.geom.PrecisionModel 实例源码

项目:com.opendoorlogistics    文件:Shapefile2TextCommand.java   
private static void convert(String inputFile, String outputFile) {
    ODLDatastoreAlterable<ODLTableAlterable> tables = TableIOUtils.importFile(new File(inputFile), ImportFileType.SHAPEFILE_COPIED_GEOM, null,null);

    ODLTable table = tables.getTableAt(0);

    // by default use 6 digit precision
    GeometryFactory factory = new GeometryFactory(new PrecisionModel(100000));
    for(int col =0 ; col< table.getColumnCount() ; col++){
        if(table.getColumnType(col)==ODLColumnType.GEOM){
            for(int row=0;row < table.getRowCount(); row++){
                ODLGeomImpl geom = (ODLGeomImpl)table.getValueAt(row, col);
                if(geom!=null){
                    // take down precision
                    Geometry geometry =geom.getJTSGeometry();
                    geometry = factory.createGeometry(geometry);

                    // set back
                    ODLLoadedGeometry loadedGeometry = new ODLLoadedGeometry(geometry);
                    table.setValueAt(loadedGeometry,row, col);
                }
            }
        }
    }
    TableIOUtils.writeToTabFile(table, new File(outputFile));
}
项目:TomboloDigitalConnector    文件:GeneralCSVImporter.java   
private Geometry getShape(CSVRecord record) {
    if (!config.getGeographyProjection().equals("") &&
            config.getGeographyXIndex() != -1 &&
            config.getGeographyYIndex() != -1) {

        GeometryFactory geometryFactory = new GeometryFactory(new PrecisionModel(), Subject.SRID);

        Coordinate coordinate = null;
        Double x = Double.parseDouble(record.get(config.getGeographyXIndex()));
        Double y = Double.parseDouble(record.get(config.getGeographyYIndex()));
        if (config.getGeographyProjection().equals(CoordinateUtils.WGS84CRS)) {

            coordinate = new Coordinate(x, y);
        } else {
            try {
                coordinate = CoordinateUtils.eastNorthToLatLong(x, y, config.getGeographyProjection(), CoordinateUtils.WGS84CRS);
            } catch (Exception e) {
                log.warn("Coordinates will not be considered: " + e.getMessage());
                return null;
            }
        }
        return geometryFactory.createPoint(coordinate);
    }

    return null;
}
项目:Earth    文件:GeometrySnapper.java   
/**
 * Estimates the snap tolerance for a Geometry, taking into account its precision model.
 *
 * @param g a Geometry
 * @return the estimated snap tolerance
 */
public static double computeOverlaySnapTolerance(Geometry g) {
    double snapTolerance = computeSizeBasedSnapTolerance(g);

    /**
     * Overlay is carried out in the precision model
     * of the two inputs.
     * If this precision model is of type FIXED, then the snap tolerance
     * must reflect the precision grid size.
     * Specifically, the snap tolerance should be at least
     * the distance from a corner of a precision grid cell
     * to the centre point of the cell.
     */
    PrecisionModel pm = g.getPrecisionModel();
    if (pm.getType() == PrecisionModel.FIXED) {
        double fixedSnapTol = (1 / pm.getScale()) * 2 / 1.415;
        if (fixedSnapTol > snapTolerance) {
            snapTolerance = fixedSnapTol;
        }
    }
    return snapTolerance;
}
项目:Earth    文件:BufferBuilder.java   
private Noder getNoder(PrecisionModel precisionModel) {
        if (this.workingNoder != null) {
            return this.workingNoder;
        }

        // otherwise use a fast (but non-robust) noder
        MCIndexNoder noder = new MCIndexNoder();
        LineIntersector li = new RobustLineIntersector();
        li.setPrecisionModel(precisionModel);
        noder.setSegmentIntersector(new IntersectionAdder(li));
//    Noder noder = new IteratedNoder(precisionModel);
        return noder;
//    Noder noder = new SimpleSnapRounder(precisionModel);
//    Noder noder = new MCIndexSnapRounder(precisionModel);
//    Noder noder = new ScaledNoder(new MCIndexSnapRounder(new PrecisionModel(1.0)),
//                                  precisionModel.getScale());
    }
项目:Earth    文件:BufferBuilder.java   
private void computeNodedEdges(List bufferSegStrList, PrecisionModel precisionModel) {
        Noder noder = this.getNoder(precisionModel);
        noder.computeNodes(bufferSegStrList);
        Collection nodedSegStrings = noder.getNodedSubstrings();
// DEBUGGING ONLY
//BufferDebug.saveEdges(nodedEdges, "run" + BufferDebug.runCount + "_nodedEdges");

        for (Object nodedSegString : nodedSegStrings) {
            SegmentString segStr = (SegmentString) nodedSegString;

            /**
             * Discard edges which have zero length,
             * since they carry no information and cause problems with topology building
             */
            Coordinate[] pts = segStr.getCoordinates();
            if (pts.length == 2 && pts[0].equals2D(pts[1])) {
                continue;
            }

            Label oldLabel = (Label) segStr.getData();
            Edge edge = new Edge(segStr.getCoordinates(), new Label(oldLabel));
            this.insertUniqueEdge(edge);
        }
        //saveEdges(edgeList.getEdges(), "run" + runCount + "_collapsedEdges");
    }
项目:Earth    文件:OffsetSegmentGenerator.java   
public OffsetSegmentGenerator(PrecisionModel precisionModel,
                              BufferParameters bufParams, double distance) {
    this.precisionModel = precisionModel;
    this.bufParams = bufParams;

    // compute intersections in full precision, to provide accuracy
    // the points are rounded as they are inserted into the curve line
    this.li = new RobustLineIntersector();
    this.filletAngleQuantum = Math.PI / 2.0 / bufParams.getQuadrantSegments();

    /**
     * Non-round joins cause issues with short closing segments, so don't use
     * them. In any case, non-round joins only really make sense for relatively
     * small buffer distances.
     */
    if (bufParams.getQuadrantSegments() >= 8
            && bufParams.getJoinStyle() == BufferParameters.JOIN_ROUND) {
        this.closingSegLengthFactor = MAX_CLOSING_SEG_LEN_FACTOR;
    }
    this.init(distance);
}
项目:Earth    文件:Densifier.java   
/**
 * Densifies a coordinate sequence.
 *
 * @param pts
 * @param distanceTolerance
 * @return the densified coordinate sequence
 */
private static Coordinate[] densifyPoints(Coordinate[] pts,
                                          double distanceTolerance, PrecisionModel precModel) {
    LineSegment seg = new LineSegment();
    CoordinateList coordList = new CoordinateList();
    for (int i = 0; i < pts.length - 1; i++) {
        seg.p0 = pts[i];
        seg.p1 = pts[i + 1];
        coordList.add(seg.p0, false);
        double len = seg.getLength();
        int densifiedSegCount = (int) (len / distanceTolerance) + 1;
        if (densifiedSegCount > 1) {
            double densifiedSegLen = len / densifiedSegCount;
            for (int j = 1; j < densifiedSegCount; j++) {
                double segFract = (j * densifiedSegLen) / len;
                Coordinate p = seg.pointAlong(segFract);
                precModel.makePrecise(p);
                coordList.add(p, false);
            }
        }
    }
    coordList.add(pts[pts.length - 1], false);
    return coordList.toCoordinateArray();
}
项目:IGSN    文件:SpatialUtilities.java   
public static Geometry wktToGeometry(String lat, String lon, SpatialType spatialType) {

        //VT: spatial store in lon/lat however mapping framework are often in lat/lon
        //http://postgis.net/2013/08/18/tip_lon_lat/
        String wkt="";
        if(spatialType == SpatialType.POINT){
             wkt = String.format("Point(%s %s)", lon,lat);
        }

        WKTReader fromText = new WKTReader(new GeometryFactory(new PrecisionModel(),4326));
        Geometry geom = null;
        try {
            geom = fromText.read(wkt);                        
        } catch (Exception e) {
            return null;
        }
        return geom;
    }
项目:gama    文件:Spatial.java   
@operator (
        value = "with_precision",
        category = { IOperatorCategory.SPATIAL, IOperatorCategory.SP_TRANSFORMATIONS },
        concept = { IConcept.GEOMETRY, IConcept.SPATIAL_COMPUTATION, IConcept.SPATIAL_TRANSFORMATION })
@doc (
        value = "A geometry corresponding to the rounding of points of the operand considering a given precison.",
        examples = { @example (
                value = "self with_precision 2",
                equals = "the geometry resulting from the rounding of points of the geometry with a precision of 0.1.",
                test = false) })
public static IShape withPrecision(final IScope scope, final IShape g1, final Integer precision) {
    if (g1 == null || g1.getInnerGeometry() == null) { return g1; }
    final double scale = Math.pow(10, precision);
    final PrecisionModel pm = new PrecisionModel(scale);
    return new GamaShape(GeometryPrecisionReducer.reduce(g1.getInnerGeometry(), pm));
}
项目:GeoSpark    文件:PolygonRDD.java   
/**
 * Polygon union.
 *
 * @return the polygon
 */
public Polygon PolygonUnion() {
    Polygon result = this.rawSpatialRDD.reduce(new Function2<Polygon, Polygon, Polygon>() {
        public Polygon call(Polygon v1, Polygon v2) {
            //Reduce precision in JTS to avoid TopologyException
            PrecisionModel pModel = new PrecisionModel();
            GeometryPrecisionReducer pReducer = new GeometryPrecisionReducer(pModel);
            Geometry p1 = pReducer.reduce(v1);
            Geometry p2 = pReducer.reduce(v2);
            //Union two polygons
            Geometry polygonGeom = p1.union(p2);
            Coordinate[] coordinates = polygonGeom.getCoordinates();
            ArrayList<Coordinate> coordinateList = new ArrayList<Coordinate>(Arrays.asList(coordinates));
            Coordinate lastCoordinate = coordinateList.get(0);
            coordinateList.add(lastCoordinate);
            Coordinate[] coordinatesClosed = new Coordinate[coordinateList.size()];
            coordinatesClosed = coordinateList.toArray(coordinatesClosed);
            GeometryFactory fact = new GeometryFactory();
            LinearRing linear = new GeometryFactory().createLinearRing(coordinatesClosed);
            Polygon polygon = new Polygon(linear, null, fact);
            //Return the two polygon union result
            return polygon;
        }
    });
    return result;
}
项目:jts    文件:OffsetSegmentGenerator.java   
public OffsetSegmentGenerator(PrecisionModel precisionModel,
                              BufferParameters bufParams, double distance) {
    this.precisionModel = precisionModel;
    this.bufParams = bufParams;

    // compute intersections in full precision, to provide accuracy
    // the points are rounded as they are inserted into the curve line
    li = new RobustLineIntersector();
    filletAngleQuantum = Math.PI / 2.0 / bufParams.getQuadrantSegments();

    /**
     * Non-round joins cause issues with short closing segments, so don't use
     * them. In any case, non-round joins only really make sense for relatively
     * small buffer distances.
     */
    if (bufParams.getQuadrantSegments() >= 8
            && bufParams.getJoinStyle() == BufferParameters.JOIN_ROUND)
        closingSegLengthFactor = MAX_CLOSING_SEG_LEN_FACTOR;
    init(distance);
}
项目:trafimage-geoserver-transformations    文件:CurveBuilder.java   
public CurveBuilder() {
    BufferParameters bufferParameters = new BufferParameters();
    bufferParameters.setEndCapStyle(BufferParameters.CAP_FLAT);
    bufferParameters.setJoinStyle(BufferParameters.JOIN_ROUND);

    /*
     * Sets the number of line segments used to approximate an angle fillet.
     * 
     *   If quadSegs >= 1, joins are round, and quadSegs indicates the number of segments to use to approximate a quarter-circle.
     *   If quadSegs = 0, joins are bevelled (flat)
        *   If quadSegs < 0, joins are mitred, and the value of qs indicates the mitre ration limit as
        *       mitreLimit = |quadSegs|
        *
        * For round joins, quadSegs determines the maximum error in the approximation to the true buffer curve. 
        * The default value of 8 gives less than 2% max error in the buffer distance. For a max error of < 1%, 
        * use QS = 12. For a max error of < 0.1%, use QS = 18. The error is always less than the buffer distance 
        * (in other words, the computed buffer curve is always inside the true curve). 
     */
    bufferParameters.setQuadrantSegments(18);

    this.curveBuilder = new OffsetCurveBuilder(new PrecisionModel(), bufferParameters);
}
项目:geodroid_master_update    文件:OffsetSegmentGenerator.java   
public OffsetSegmentGenerator(PrecisionModel precisionModel,
    BufferParameters bufParams, double distance) {
  this.precisionModel = precisionModel;
  this.bufParams = bufParams;

  // compute intersections in full precision, to provide accuracy
  // the points are rounded as they are inserted into the curve line
  li = new RobustLineIntersector();
  filletAngleQuantum = Math.PI / 2.0 / bufParams.getQuadrantSegments();

  /**
   * Non-round joins cause issues with short closing segments, so don't use
   * them. In any case, non-round joins only really make sense for relatively
   * small buffer distances.
   */
  if (bufParams.getQuadrantSegments() >= 8
      && bufParams.getJoinStyle() == BufferParameters.JOIN_ROUND)
    closingSegLengthFactor = MAX_CLOSING_SEG_LEN_FACTOR;
  init(distance);
}
项目:geowave    文件:PropertyManagement.java   
@Override
public DistributableQuery convert(
        final Serializable ob )
        throws Exception {
    if (ob instanceof byte[]) {
        return (DistributableQuery) PropertyManagement.fromBytes((byte[]) ob);
    }
    final PrecisionModel precision = new PrecisionModel();
    final GeometryFactory geometryFactory = new GeometryFactory(
            precision,
            4326);
    final WKTReader wktReader = new WKTReader(
            geometryFactory);
    return new SpatialQuery(
            wktReader.read(ob.toString()));
}
项目:geomajas-project-client-gwt    文件:GwtMultiLineStringTest.java   
public GwtMultiLineStringTest() {
    gwtFactory = new GeometryFactory(SRID, PRECISION);
    LineString gwtLine1 = gwtFactory.createLineString(new Coordinate[] {new Coordinate(10.0, 10.0),
            new Coordinate(20.0, 10.0), new Coordinate(20.0, 20.0)});
    LineString gwtLine2 = gwtFactory.createLineString(new Coordinate[] {new Coordinate(10.0, 20.0),
            new Coordinate(30.0, 10.0), new Coordinate(40.0, 10.0)});
    gwt = gwtFactory.createMultiLineString(new LineString[] {gwtLine1, gwtLine2});

    jtsFactory = new com.vividsolutions.jts.geom.GeometryFactory(new PrecisionModel(), SRID);
    com.vividsolutions.jts.geom.LineString jtsLine1 = jtsFactory
            .createLineString(new com.vividsolutions.jts.geom.Coordinate[] {
                    new com.vividsolutions.jts.geom.Coordinate(10.0, 10.0),
                    new com.vividsolutions.jts.geom.Coordinate(20.0, 10.0),
                    new com.vividsolutions.jts.geom.Coordinate(20.0, 20.0)});
    com.vividsolutions.jts.geom.LineString jtsLine2 = jtsFactory
            .createLineString(new com.vividsolutions.jts.geom.Coordinate[] {
                    new com.vividsolutions.jts.geom.Coordinate(10.0, 20.0),
                    new com.vividsolutions.jts.geom.Coordinate(30.0, 10.0),
                    new com.vividsolutions.jts.geom.Coordinate(40.0, 10.0)});
    jts = jtsFactory.createMultiLineString(new com.vividsolutions.jts.geom.LineString[] {jtsLine1, jtsLine2});
}
项目:geomajas-project-client-gwt    文件:GwtPolygonTest.java   
/**
 * Creates polygons with a single hole in them.
 */
public GwtPolygonTest() {
    gwtFactory = new GeometryFactory(SRID, PRECISION);
    LinearRing gwtShell = gwtFactory.createLinearRing(new Coordinate[] { new Coordinate(10.0, 10.0),
            new Coordinate(20.0, 10.0), new Coordinate(20.0, 20.0), new Coordinate(10.0, 10.0) });
    LinearRing gwtHole = gwtFactory.createLinearRing(new Coordinate[] { new Coordinate(12.0, 12.0),
            new Coordinate(18.0, 12.0), new Coordinate(18.0, 18.0), new Coordinate(12.0, 12.0) });
    gwt = gwtFactory.createPolygon(gwtShell, new LinearRing[] { gwtHole });
    noholes = gwtFactory.createPolygon(gwtShell, null);

    jtsFactory = new com.vividsolutions.jts.geom.GeometryFactory(new PrecisionModel(), SRID);
    com.vividsolutions.jts.geom.LinearRing jtsShell = jtsFactory
            .createLinearRing(new com.vividsolutions.jts.geom.Coordinate[] {
                    new com.vividsolutions.jts.geom.Coordinate(10.0, 10.0),
                    new com.vividsolutions.jts.geom.Coordinate(20.0, 10.0),
                    new com.vividsolutions.jts.geom.Coordinate(20.0, 20.0),
                    new com.vividsolutions.jts.geom.Coordinate(10.0, 10.0) });
    com.vividsolutions.jts.geom.LinearRing jtsHole = jtsFactory
            .createLinearRing(new com.vividsolutions.jts.geom.Coordinate[] {
                    new com.vividsolutions.jts.geom.Coordinate(12.0, 12.0),
                    new com.vividsolutions.jts.geom.Coordinate(18.0, 12.0),
                    new com.vividsolutions.jts.geom.Coordinate(18.0, 18.0),
                    new com.vividsolutions.jts.geom.Coordinate(12.0, 12.0) });
    jts = jtsFactory.createPolygon(jtsShell, new com.vividsolutions.jts.geom.LinearRing[] { jtsHole });
}
项目:geomajas-project-server    文件:BeanFeatureModel.java   
public Geometry getGeometry(Object feature) throws LayerException {
    Entity entity = entityMapper.asEntity(feature);
    Object geometry = entity.getAttribute(getGeometryAttributeName());
    if (!wkt || null == geometry) {
        log.debug("bean.getGeometry {}", geometry);
        return (Geometry) geometry;
    } else {
        try {
            WKTReader reader = new WKTReader(new GeometryFactory(new PrecisionModel(), srid));
            Geometry geom = reader.read((String) geometry);
            log.debug("bean.getGeometry {}", geom);
            return geom;
        } catch (Throwable t) {
            throw new LayerException(t, ExceptionCode.FEATURE_MODEL_PROBLEM, geometry);
        }
    }
}
项目:geomajas-project-server    文件:GeoServiceTest.java   
@Test
public void testCreateCircle() throws Exception {
    Geometry geometry;
    GeometryFactory factory = new GeometryFactory(new PrecisionModel(), 4326);
    Point point = factory.createPoint(new Coordinate(0, 0));
    Point inside = factory.createPoint(new Coordinate(9.5, 0));
    Point insideFine = factory.createPoint(new Coordinate(6.8, 6.8));
    Point outsideAll = factory.createPoint(new Coordinate(9, 5));

    geometry = geoService.createCircle(point, 10, 4);
    Assert.assertEquals(5, geometry.getCoordinates().length);
    Assert.assertTrue(geometry.contains(inside));
    Assert.assertFalse(geometry.contains(insideFine));
    Assert.assertFalse(geometry.contains(outsideAll));

    geometry = geoService.createCircle(point, 10, 16);
    Assert.assertEquals(17, geometry.getCoordinates().length);
    Assert.assertTrue(geometry.contains(inside));
    Assert.assertTrue(geometry.contains(insideFine));
    Assert.assertFalse(geometry.contains(outsideAll));
}
项目:geomajas-project-server    文件:GeometryConverterTest.java   
public GeometryConverterTest() {
    factory = new GeometryFactory(new PrecisionModel(), SRID);
    jtsC1 = new com.vividsolutions.jts.geom.Coordinate(10.0, 10.0);
    jtsC2 = new com.vividsolutions.jts.geom.Coordinate(20.0, 10.0);
    jtsC3 = new com.vividsolutions.jts.geom.Coordinate(20.0, 20.0);
    jtsC4 = new com.vividsolutions.jts.geom.Coordinate(10.0, 20.0);
    jtsC5 = new com.vividsolutions.jts.geom.Coordinate(12.0, 12.0);
    jtsC6 = new com.vividsolutions.jts.geom.Coordinate(12.0, 18.0);
    jtsC7 = new com.vividsolutions.jts.geom.Coordinate(18.0, 18.0);
    jtsC8 = new com.vividsolutions.jts.geom.Coordinate(18.0, 12.0);

    dtoC1 = new Coordinate(10.0, 10.0);
    dtoC2 = new Coordinate(20.0, 10.0);
    dtoC3 = new Coordinate(20.0, 20.0);
    dtoC4 = new Coordinate(10.0, 20.0);
    dtoC5 = new Coordinate(12.0, 12.0);
    dtoC6 = new Coordinate(12.0, 18.0);
    dtoC7 = new Coordinate(18.0, 18.0);
    dtoC8 = new Coordinate(18.0, 12.0);
}
项目:jeql    文件:TableShpWriter.java   
/**
 * return a single geometry collection <Br>
 * result.GeometryN(i) = the i-th feature in the FeatureCollection<br>
 * All the geometry types will be the same type (ie. all polygons) - or they
 * will be set to<br>
 * NULL geometries<br>
 * <br>
 * GeometryN(i) = {Multipoint,Multilinestring, or Multipolygon)<br>
 * 
 * @param rows
 *          input rows
 * @param geomIndex
 *          index of geometry in row
 */
public GeometryCollection creatShpGeometryCollection(List rows, int geomIndex)
    throws Exception {
  Geometry[] allGeoms = new Geometry[rows.size()];

  int geomtype = findBestGeometryType(rows, geomIndex);

  if (geomtype == 0) {
    throw new IllegalArgumentException(
        "Could not determine shapefile geometry type (data is either empty or all GeometryCollections)");
  }

  for (int t = 0; t < rows.size(); t++) {
    Row row = (Row) rows.get(t);
    Geometry geom = (Geometry) row.getValue(geomIndex);

    allGeoms[t] = ShapeGeometryBuilder.buildGeometry(geom, geomtype);
  }
  GeometryCollection result = new GeometryCollection(allGeoms,
      new PrecisionModel(), 0);
  return result;
}
项目:terraingis    文件:OffsetSegmentGenerator.java   
public OffsetSegmentGenerator(PrecisionModel precisionModel,
    BufferParameters bufParams, double distance) {
  this.precisionModel = precisionModel;
  this.bufParams = bufParams;

  // compute intersections in full precision, to provide accuracy
  // the points are rounded as they are inserted into the curve line
  li = new RobustLineIntersector();
  filletAngleQuantum = Math.PI / 2.0 / bufParams.getQuadrantSegments();

  /**
   * Non-round joins cause issues with short closing segments, so don't use
   * them. In any case, non-round joins only really make sense for relatively
   * small buffer distances.
   */
  if (bufParams.getQuadrantSegments() >= 8
      && bufParams.getJoinStyle() == BufferParameters.JOIN_ROUND)
    closingSegLengthFactor = MAX_CLOSING_SEG_LEN_FACTOR;
  init(distance);
}
项目:geomajas-project-geometry    文件:GeometryConverterTest.java   
public GeometryConverterTest() {
    factory = new GeometryFactory(new PrecisionModel(), SRID);
    jtsC1 = new com.vividsolutions.jts.geom.Coordinate(10.0, 10.0);
    jtsC2 = new com.vividsolutions.jts.geom.Coordinate(20.0, 10.0);
    jtsC3 = new com.vividsolutions.jts.geom.Coordinate(20.0, 20.0);
    jtsC4 = new com.vividsolutions.jts.geom.Coordinate(10.0, 20.0);
    jtsC5 = new com.vividsolutions.jts.geom.Coordinate(12.0, 12.0);
    jtsC6 = new com.vividsolutions.jts.geom.Coordinate(12.0, 18.0);
    jtsC7 = new com.vividsolutions.jts.geom.Coordinate(18.0, 18.0);
    jtsC8 = new com.vividsolutions.jts.geom.Coordinate(18.0, 12.0);

    dtoC1 = new Coordinate(10.0, 10.0);
    dtoC2 = new Coordinate(20.0, 10.0);
    dtoC3 = new Coordinate(20.0, 20.0);
    dtoC4 = new Coordinate(10.0, 20.0);
    dtoC5 = new Coordinate(12.0, 12.0);
    dtoC6 = new Coordinate(12.0, 18.0);
    dtoC7 = new Coordinate(18.0, 18.0);
    dtoC8 = new Coordinate(18.0, 12.0);
}
项目:geomajas-project-geometry    文件:GeometryServiceMultiPointTest.java   
@Before
public void setUp() {
    Geometry point1 = new Geometry(Geometry.POINT, SRID, 0);
    point1.setCoordinates(new Coordinate[] { new Coordinate(10.0, 10.0) });
    Geometry point2 = new Geometry(Geometry.POINT, SRID, 0);
    point2.setCoordinates(new Coordinate[] { new Coordinate(10.0, 20.0) });
    Geometry point3 = new Geometry(Geometry.POINT, SRID, 0);
    point3.setCoordinates(new Coordinate[] { new Coordinate(20.0, 20.0) });

    gwt = new Geometry(Geometry.MULTI_POINT, SRID, 0);
    gwt.setGeometries(new Geometry[] { point1, point2, point3 });

    jtsFactory = new com.vividsolutions.jts.geom.GeometryFactory(new PrecisionModel(), SRID);
    jts = jtsFactory.createMultiPoint(new com.vividsolutions.jts.geom.Coordinate[] {
            new com.vividsolutions.jts.geom.Coordinate(10.0, 10.0),
            new com.vividsolutions.jts.geom.Coordinate(10.0, 20.0),
            new com.vividsolutions.jts.geom.Coordinate(20.0, 20.0) });
}
项目:geomajas-project-geometry    文件:GeometryServiceMultiLineStringTest.java   
@Before
public void setUp() {
    Geometry gwtLine1 = new Geometry(Geometry.LINE_STRING, SRID, 0);
    gwtLine1.setCoordinates(new Coordinate[] { new Coordinate(10.0, 10.0), new Coordinate(20.0, 10.0),
            new Coordinate(20.0, 20.0) });
    Geometry gwtLine2 = new Geometry(Geometry.LINE_STRING, SRID, 0);
    gwtLine2.setCoordinates(new Coordinate[] { new Coordinate(10.0, 20.0), new Coordinate(30.0, 10.0),
            new Coordinate(40.0, 10.0) });
    gwt = new Geometry(Geometry.MULTI_LINE_STRING, SRID, 0);
    gwt.setGeometries(new Geometry[] { gwtLine1, gwtLine2 });

    jtsFactory = new com.vividsolutions.jts.geom.GeometryFactory(new PrecisionModel(), SRID);
    com.vividsolutions.jts.geom.LineString jtsLine1 = jtsFactory
            .createLineString(new com.vividsolutions.jts.geom.Coordinate[] {
                    new com.vividsolutions.jts.geom.Coordinate(10.0, 10.0),
                    new com.vividsolutions.jts.geom.Coordinate(20.0, 10.0),
                    new com.vividsolutions.jts.geom.Coordinate(20.0, 20.0) });
    com.vividsolutions.jts.geom.LineString jtsLine2 = jtsFactory
            .createLineString(new com.vividsolutions.jts.geom.Coordinate[] {
                    new com.vividsolutions.jts.geom.Coordinate(10.0, 20.0),
                    new com.vividsolutions.jts.geom.Coordinate(30.0, 10.0),
                    new com.vividsolutions.jts.geom.Coordinate(40.0, 10.0) });
    jts = jtsFactory.createMultiLineString(new com.vividsolutions.jts.geom.LineString[] { jtsLine1, jtsLine2 });
}
项目:C4SG-Obsolete    文件:UserMapper.java   
/**
 * Map user data transfer object into user entity
 * 
 * @param userDTO User Data Transfer object
 * @return User
 */ 
public User getUserEntityFromDto(UserDTO userDTO){
    User user = map(userDTO, User.class);

    if (userDTO.getLatitude() != null && userDTO.getLongitude() != null){
        GeometryFactory gf = new GeometryFactory(new PrecisionModel(PrecisionModel.FLOATING));
        Coordinate coordinate = new Coordinate(Double.parseDouble(userDTO.getLongitude()),
                Double.parseDouble(userDTO.getLatitude()));
        com.vividsolutions.jts.geom.Point point = gf.createPoint(coordinate);   
        user.setLocation(point);            
    }
    user.setDisplayFlag(Boolean.valueOf(userDTO.getDisplayFlag()));
    return user;
}
项目:C4SG-Obsolete    文件:UserMapper.java   
/**
 * Map user data transfer object into user entity
 * 
 * @param userDTO User Data Transfer object
 * @return User
 */ 
public User getUserEntityFromDto(UserDTO userDTO){
    User user = map(userDTO, User.class);

    if (userDTO.getLatitude() != null && userDTO.getLongitude() != null){
        GeometryFactory gf = new GeometryFactory(new PrecisionModel(PrecisionModel.FLOATING));
        Coordinate coordinate = new Coordinate(Double.parseDouble(userDTO.getLongitude()),
                Double.parseDouble(userDTO.getLatitude()));
        com.vividsolutions.jts.geom.Point point = gf.createPoint(coordinate);   
        user.setLocation(point);            
    }
    user.setDisplayFlag(Boolean.valueOf(userDTO.getDisplayFlag()));
    return user;
}
项目:ThriftyPaxos    文件:ValueGeometry.java   
/**
 * Get or create a geometry value for the given geometry.
 *
 * @param s the WKT representation of the geometry
 * @param srid the srid of the object
 * @return the value
 */
public static ValueGeometry get(String s, int srid) {
    try {
        GeometryFactory geometryFactory = new GeometryFactory(new PrecisionModel(), srid);
        Geometry g = new WKTReader(geometryFactory).read(s);
        return get(g);
    } catch (ParseException ex) {
        throw DbException.convert(ex);
    }
}
项目:oma-riista-web    文件:GISUtils.java   
private static List createSTRTreeIndex(final List<Geometry> geomList) {
    final STRtree index = new STRtree(16);

    final PrecisionModel pm = new PrecisionModel(1000000);
    for (final Geometry item : geomList) {
        final Geometry g = GeometryPrecisionReducer.reduce(item, pm);
        index.insert(g.getEnvelopeInternal(), g);
    }

    return index.itemsTree();
}
项目:TomboloDigitalConnector    文件:HealthOrganisationImporter.java   
@Override
protected void importDatasource(Datasource datasource, List<String> geographyScope, List<String> temporalScope, List<String> datasourceLocation) throws Exception {

    GeometryFactory geometryFactory = new GeometryFactory(new PrecisionModel(), Subject.SRID);
    JSONObject documentObj = downloadUtils.fetchJSON(new URL(datasource.getDatasourceSpec().getUrl()), getProvider().getLabel());

    List<Map<String, String>> results = (List<Map<String, String>>) documentObj.get("result");

    List<Subject> subjects = results.stream().map(healthOrgObj -> {
        String label = healthOrgObj.get("organisation_id");
        String name = healthOrgObj.get("organisation_name");
        Point point = null;
        try {
            Double longitude = Double.parseDouble(healthOrgObj.get("longitude"));
            Double latitude = Double.parseDouble(healthOrgObj.get("latitude"));
            Coordinate coordinate = new Coordinate(longitude, latitude);
            point = geometryFactory.createPoint(coordinate);

            // FIXME: Add fixed values

        } catch (Exception e) {
            // If we have any trouble with the geometry, e.g. the figures are blank or invalid,
            // we use the null geometry prepopulated in the `point` variable, and log.
            log.warn("Health organisation {} ({}) has no valid geometry", name, label);
        }
        return new Subject(datasource.getUniqueSubjectType(), label, name, point);

    }).collect(Collectors.toList());

    saveAndClearSubjectBuffer(subjects);
}
项目:Earth    文件:OffsetCurveBuilder.java   
public OffsetCurveBuilder(
        PrecisionModel precisionModel,
        BufferParameters bufParams
) {
    this.precisionModel = precisionModel;
    this.bufParams = bufParams;
}
项目:Earth    文件:BufferOp.java   
private void computeGeometry() {
    this.bufferOriginalPrecision();
    if (this.resultGeometry != null) {
        return;
    }

    PrecisionModel argPM = this.argGeom.getFactory().getPrecisionModel();
    if (argPM.getType() == PrecisionModel.FIXED) {
        this.bufferFixedPrecision(argPM);
    } else {
        this.bufferReducedPrecision();
    }
}
项目:Earth    文件:BufferOp.java   
private void bufferReducedPrecision(int precisionDigits) {
        double sizeBasedScaleFactor = precisionScaleFactor(this.argGeom, this.distance, precisionDigits);
//    System.out.println("recomputing with precision scale factor = " + sizeBasedScaleFactor);

        PrecisionModel fixedPM = new PrecisionModel(sizeBasedScaleFactor);
        this.bufferFixedPrecision(fixedPM);
    }
项目:Earth    文件:BufferOp.java   
private void bufferFixedPrecision(PrecisionModel fixedPM) {
    Noder noder = new ScaledNoder(new MCIndexSnapRounder(new PrecisionModel(1.0)),
            fixedPM.getScale());

    BufferBuilder bufBuilder = new BufferBuilder(this.bufParams);
    bufBuilder.setWorkingPrecisionModel(fixedPM);
    bufBuilder.setNoder(noder);
    // this may throw an exception, if robustness errors are encountered
    this.resultGeometry = bufBuilder.buffer(this.argGeom, this.distance);
}
项目:Earth    文件:GeometryPrecisionReducer.java   
private GeometryEditor createEditor(GeometryFactory geomFactory, PrecisionModel newPM) {
    // no need to change if precision model is the same
    if (geomFactory.getPrecisionModel() == newPM) {
        return new GeometryEditor();
    }
    // otherwise create a geometry editor which changes PrecisionModel
    GeometryFactory newFactory = this.createFactory(geomFactory, newPM);
    GeometryEditor geomEdit = new GeometryEditor(newFactory);
    return geomEdit;
}
项目:Earth    文件:GeometryPrecisionReducer.java   
private GeometryFactory createFactory(GeometryFactory inputFactory, PrecisionModel pm) {
    GeometryFactory newFactory
            = new GeometryFactory(pm,
            inputFactory.getSRID(),
            inputFactory.getCoordinateSequenceFactory());
    return newFactory;
}
项目:Earth    文件:WKTWriter.java   
/**
 * Creates the <code>DecimalFormat</code> used to write <code>double</code>s
 * with a sufficient number of decimal places.
 *
 * @param precisionModel the <code>PrecisionModel</code> used to determine
 * the number of decimal places to write.
 * @return a <code>DecimalFormat</code> that write <code>double</code>
 * s without scientific notation.
 */
private static DecimalFormat createFormatter(PrecisionModel precisionModel) {
    // the default number of decimal places is 16, which is sufficient
    // to accomodate the maximum precision of a double.
    int decimalPlaces = precisionModel.getMaximumSignificantDigits();
    // specify decimal separator explicitly to avoid problems in other locales
    DecimalFormatSymbols symbols = new DecimalFormatSymbols();
    symbols.setDecimalSeparator('.');
    String fmtString = "0" + (decimalPlaces > 0 ? "." : "")
            + stringOfChar('#', decimalPlaces);
    return new DecimalFormat(fmtString, symbols);
}
项目:Earth    文件:WKTWriter.java   
/**
 * Converts a <code>Coordinate</code> to &lt;Point Text&gt; format, then
 * appends it to the writer.
 *
 * @param coordinate the <code>Coordinate</code> to process
 * @param writer the output writer to append to
 * @param precisionModel the <code>PrecisionModel</code> to use to convert
 * from a precise coordinate to an external coordinate
 */
private void appendPointText(Coordinate coordinate, int level, Writer writer,
                             PrecisionModel precisionModel)
        throws IOException {
    if (coordinate == null) {
        writer.write("EMPTY");
    } else {
        writer.write("(");
        this.appendCoordinate(coordinate, writer);
        writer.write(")");
    }
}
项目:igsn30    文件:SpatialUtilities.java   
public static Geometry wktToGeometry(String wkt,String sridXML) throws ParseException {

        int srid = Integer.parseInt(sridXML.replace("https://epsg.io/", ""));


        WKTReader fromText = new WKTReader(new GeometryFactory(new PrecisionModel(),srid));
        Geometry geom = null;
        try {
            geom = fromText.read(wkt);
            if( srid != 4326){
                CoordinateReferenceSystem sourceCRS = CRS.decode("EPSG:" + srid);
                CoordinateReferenceSystem targetCRS = CRS.decode("EPSG:4326");              
                MathTransform transform = CRS.findMathTransform(sourceCRS, targetCRS);
                geom = JTS.transform( geom, transform);
                geom.setSRID(4326);

                //VT: For some reason this transformation swapped X and Y around for EPGS:4326 vs the others
//              Coordinate[] original = geom.getCoordinates();
//                for(int i =0; i<original.length; i++){
//                    Double swapValue = original[i].x;
//                    original[i].x = original[i].y;
//                    original[i].y = swapValue;
//                }
            }

        } catch (Exception e) {
            throw new ParseException("Unable to parse and convert WKT");
        }
        return geom;
    }
项目:sldeditor    文件:WKTConversion.java   
/**
 * Convert to com.vividsolutions.jts.geom geometry.
 *
 * @param wktString the wkt string
 * @param crsCode the crs code
 * @return the geometry
 */
public static Geometry convertToGeometry(String wktString, String crsCode) {
    int srid = 0;

    if (crsCode != null) {
        CoordinateReferenceSystem crs = CoordManager.getInstance().getCRS(crsCode);
        String sridString = CRS.toSRS(crs, true);
        srid = Integer.valueOf(sridString).intValue();
    }
    com.vividsolutions.jts.geom.GeometryFactory geometryFactory =
            new com.vividsolutions.jts.geom.GeometryFactory(
            new PrecisionModel(), srid);

    WKTReader parser = new WKTReader(geometryFactory);

    if (wktString.startsWith(WKT_PREFIX)) {
        wktString = wktString.substring(WKT_PREFIX.length());
    }

    Geometry shape = null;
    try {
        shape = parser.read(wktString);
    } catch (com.vividsolutions.jts.io.ParseException e) {
        ConsoleManager.getInstance().exception(WKTConversion.class, e);
    }

    return shape;
}
项目:gml3-jts    文件:GML3112ParserImpl.java   
/**
 * <p>Constructor for GML3112ParserImpl.</p>
 *
 * @param maximumArcApproximationError a double.
 * @param srid a int.
 */
public GML3112ParserImpl(final double maximumArcApproximationError, final int srid) {
    ExtendedGeometryFactory geometryFactory = new ExtendedGeometryFactory(new PrecisionModel(), srid);
    geometryFactory.setMaximumArcApproximationError(maximumArcApproximationError);
    this.gmlToJTSGeometryConvertor = new GMLToJTSGeometryConvertor(geometryFactory);

    LOGGER.info("Created a GML 3.1.1.2 parser for SRID {} with MaximumArcApproximationError {}", srid, maximumArcApproximationError);
}