org.geotools.geometry.jts.JTS类的使用及代码示例

x33g5p2x  于2022-01-21 转载在 其他  
字(14.8k)|赞(0)|评价(0)|浏览(349)

本文整理了Java中org.geotools.geometry.jts.JTS类的一些代码示例,展示了JTS类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。JTS类的具体详情如下:
包路径:org.geotools.geometry.jts.JTS
类名称:JTS

JTS介绍

[英]JTS Geometry utility methods, bringing Geotools to JTS.

Offers geotools based services such as reprojection.

Responsibilities:

  • transformation
  • coordinate sequence editing
  • common coordinate sequence implementations for specific uses
    [中]JTS几何实用方法,将Geotools引入JTS。
    提供基于geotools的服务,如重投影。
    责任:
    *转化
    *坐标序列编辑
    *特定用途的通用坐标序列实现

代码示例

代码示例来源:origin: opentripplanner/OpenTripPlanner

CoordinateReferenceSystem crs = CRS.decode(crsCode);
MathTransform toMeters   = CRS.findMathTransform(wgs, crs, false);
MathTransform fromMeters = CRS.findMathTransform(crs, wgs, false); 
GeometryFactory geomf = JTSFactoryFinder.getGeometryFactory();
    if (remainingSeconds > 60) { // avoid degenerate geometries
      double remainingMeters = remainingSeconds * request.walkSpeed;
      Geometry point = geomf.createPoint(vertexSeconds.getKey().getCoordinate());
      point = JTS.transform(point, toMeters);
      Geometry buffer = point.buffer(remainingMeters);
      bufferLists.put(thresholdSeconds, buffer);
for (Integer threshold : bufferLists.keys()) {
  Collection<Geometry> buffers = bufferLists.get(threshold);
  Geometry geom = geomf.buildGeometry(buffers); // make geometry collection
  geom = geom.union(); // combine all individual buffers in this contour into one
  if ( ! resultsProjected) geom = JTS.transform(geom, fromMeters);
  contours.put(threshold, geom);

代码示例来源:origin: geoserver/geoserver

JTS.toGeometry((Envelope) new ReferencedEnvelope(grid.getEnvelope2D()));
if (coverageBounds.intersects(rasterFilter)) {
  final ParameterValueGroup param = cropParams.clone();

代码示例来源:origin: geotools/geotools

/**
 * Creates a {@link CoordinateSequence} using the provided factory confirming the provided size
 * and dimension are respected.
 *
 * <p>If the requested dimension is larger than the CoordinateSequence implementation can
 * provide, then a sequence of maximum possible dimension should be created. An error should not
 * be thrown.
 *
 * <p>This method is functionally identical to calling csFactory.create(size,dim) - it contains
 * additional logic to work around a limitation on the commonly used
 * CoordinateArraySequenceFactory.
 *
 * @param size the number of coordinates in the sequence
 * @param dimension the dimension of the coordinates in the sequence
 */
public static CoordinateSequence createCS(
    CoordinateSequenceFactory csFactory, int size, int dimension) {
  // the coordinates don't have measures
  return createCS(csFactory, size, dimension, 0);
}

代码示例来源:origin: au.gov.amsa.risky/geo-analyzer

public static Point createPoint(double lat, double lon, String srsName) {
  GeometryFactory geometryFactory = new GeometryFactory();
  Coordinate coordinate = new Coordinate(lon, lat);
  Point point = geometryFactory.createPoint(coordinate);
  try {
    if (!srsName.equals(EPSG_4326)) {
      MathTransform transform = CRS.findMathTransform(getCrs(EPSG_4326), getCrs(srsName));
      point = (Point) JTS.transform(point, transform);
    }
    return point;
  } catch (NoSuchAuthorityCodeException e) {
    throw new RuntimeException(e);
  } catch (FactoryException e) {
    throw new RuntimeException(e);
  } catch (MismatchedDimensionException e) {
    throw new RuntimeException(e);
  } catch (TransformException e) {
    throw new RuntimeException(e);
  }
}

代码示例来源:origin: org.geotools/gt-process-raster

throw new ProcessException("height and width parameters must be greater than 0");
if (bounds.getCoordinateReferenceSystem() == null) {
  throw new ProcessException("Envelope CRS must not be null");
GeometryFactory geomFactory = new GeometryFactory();
try {
  Polygon polygon = null;
  CoordinateReferenceSystem targetCRS = CRS.parseWKT(targetCRSWKT);
  MathTransform transform = CRS.findMathTransform(sourceCRS, targetCRS);
  double pX = bounds.getMinX();
  double pY = bounds.getMaxY();
  double stepX = (bounds.getMaxX() - bounds.getMinX()) / width;
  double stepY = (bounds.getMaxY() - bounds.getMinY()) / height;
        tempCoordinates[2].x = nX; tempCoordinates[2].y = nY;
        tempCoordinates[3].x = pX; tempCoordinates[3].y = nY;
        polygon.geometryChanged();
      Geometry targetGeometry = JTS.transform(polygon, transform);
      matrix[i][j] = (float) targetGeometry.getArea();

代码示例来源:origin: geotools/geotools

@Test
public void testUTMDatelineWrapping() throws Exception {
  CoordinateReferenceSystem crs = CRS.decode("EPSG:32601", true);
  ReferencedEnvelope re = new ReferencedEnvelope(300000, 409800, 5890200, 6000000, crs);
  MathTransform mt = CRS.findMathTransform(crs, WGS84);
  Geometry geom = JTS.toGeometry(re);
  ReferencedEnvelope targetReferenceEnvelope =
      new ReferencedEnvelope(-180, 180, -90, 90, WGS84);
  ProjectionHandler ph =
      ProjectionHandlerFinder.getHandler(targetReferenceEnvelope, crs, true);
  Geometry preProcessed = ph.preProcess(geom);
  Geometry transformed = JTS.transform(preProcessed, mt);
  Geometry postProcessed = ph.postProcess(mt.inverse(), transformed);
  // sits across the dateline and it's "small" (used to cover the entire planet)
  Envelope ppEnvelope = postProcessed.getGeometryN(0).getEnvelopeInternal();
  assertTrue(ppEnvelope.contains(180, 54));
  // the original width is 109km, at this latitude one degree of longitude is only 65km
  assertEquals(1.7, ppEnvelope.getWidth(), 0.1);
}

代码示例来源:origin: org.geotools/gt-render

final CoordinateReferenceSystem tempCRS = CRS.getHorizontalCRS(coordinateReferenceSystem);
if(tempCRS==null)
  throw new TransformException(Errors.format(
final Coordinate p1 = new Coordinate(envelope.getMinX(), envelope
    .getMinY());
final Coordinate p2 = new Coordinate(envelope.getMaxX(), envelope
    .getMaxY());
cs[0] = p1.x;
final MathTransform transform = CRS.findMathTransform(tempCRS,
    DefaultGeographicCRS.WGS84, true);
transform.transform(cs, 0, csLatLong, 0, 2);
      / envelope.getHeight() * imageHeight;
  double distance_ground = JTS.orthodromicDistance(new Coordinate(
      newCsLatLong[0], newCsLatLong[1]), new Coordinate(
      newCsLatLong[2], newCsLatLong[3]),
double diagonalGroundDistance = JTS.orthodromicDistance(new Coordinate(
    csLatLong[0], csLatLong[1]), new Coordinate(csLatLong[2],
    csLatLong[3]), DefaultGeographicCRS.WGS84);

代码示例来源:origin: senbox-org/s2tbx

private ReferencedEnvelope transformEnvelope(CoordinateReferenceSystem fromCRS,
                       CoordinateReferenceSystem toCRS,
                       Rectangle2D bounds) {
  try {
    MathTransform transform = CRS.findMathTransform(fromCRS, toCRS);
    Envelope sourceEnvelope = new Envelope(bounds.getMinX(), bounds.getMaxX(),
        bounds.getMinY(), bounds.getMaxY());
    final Envelope envelope = JTS.transform(sourceEnvelope, transform);
    return new ReferencedEnvelope(envelope.getMinX(), envelope.getMaxX(),
        envelope.getMinY(), envelope.getMaxY(),
        toCRS);
  } catch (FactoryException | TransformException e) {
    e.printStackTrace();
    return null;
  }
}

代码示例来源:origin: org.integratedmodelling/klab-engine

if (dataEnvelope != null) {
  try {
    geometry = JTS.transform(geometry, CRS
        .findMathTransform(dataEnvelope.getCoordinateReferenceSystem(), ((Grid)extent).getCRS()));
  } catch (Exception e) {
    return;
  for (int i = 0; i < geometry.getNumGeometries(); i++) {
    Polygon poly = (Polygon) geometry.getGeometryN(i);
    LinearRing lr = geoFactory.createLinearRing(poly.getExteriorRing().getCoordinates());
    Polygon part = geoFactory.createPolygon(lr, null);
    drawGeometry(part, false, swapAxis);
    for (int j = 0; j < poly.getNumInteriorRing(); j++) {
      lr = geoFactory.createLinearRing(poly.getInteriorRingN(j).getCoordinates());
      part = geoFactory.createPolygon(lr, null);
      drawGeometry(part, true, swapAxis);

代码示例来源:origin: mapplus/spatial_statistics_for_geotools_udig

if (cropShape == null || cropShape.isEmpty()) {
  roi = null;
} else {
  if (geomBinding.isAssignableFrom(MultiPolygon.class)
      || geomBinding.isAssignableFrom(Polygon.class)) {
    if (!cropShape.isValid() || !cropShape.isSimple()) {
      cropShape = cropShape.buffer(0);
      cropShape.setUserData(cropShape.getUserData());
    roi = (GeometryCollection) cropShape;
  } else {
    roi = cropShape.getFactory().createGeometryCollection(new Geometry[] { cropShape });
if (extent == null || extent.isEmpty() || extent.isNull()) {
  if (roi != null) {
    bounds = new GeneralEnvelope(new ReferencedEnvelope(roi.getEnvelopeInternal(), crs));
  CoordinateReferenceSystem extCrs = extent.getCoordinateReferenceSystem();
  if (!CRS.equalsIgnoreMetadata(crs, extCrs)) {
    try {
      MathTransform transform = CRS.findMathTransform(extCrs, crs, true);
      Envelope env = JTS.transform(extent, transform);
      bounds = new GeneralEnvelope(new ReferencedEnvelope(env, crs));
    } catch (FactoryException e) {

代码示例来源:origin: geotools/geotools

@Test
public void testCutGeometryLambertConformal() throws Exception {
  // get a lambert conformal conic with
  ReferencedEnvelope wgs84South = new ReferencedEnvelope(-180, -90, -40, 0, WGS84);
  ReferencedEnvelope laeSouth = wgs84South.transform(CRS.decode("EPSG:2194"), true);
  ProjectionHandler handler = ProjectionHandlerFinder.getHandler(laeSouth, WGS84, true);
  // a Geometry that crosses the opposite of the central meridian
  Polygon geometry = JTS.toGeometry(new Envelope(5, 15, 0, 10));
  Geometry preProcessed = handler.preProcess(geometry);
  assertTrue(
      "Should have sliced the geometry in two parts",
      preProcessed instanceof MultiPolygon);
}

代码示例来源:origin: org.geoserver/gwc

return JTS.toGeometry(new Envelope(prescribedBounds.getMinX(), prescribedBounds
      .getMaxX(), prescribedBounds.getMinY(), prescribedBounds.getMaxY()));
final org.opengis.geometry.Envelope envelope = CRS.getEnvelope(targetCrs);
if (envelope == null) {
  return null;
if (envelope.getSpan(0) < tolerance || envelope.getSpan(1) < tolerance) {
  GeographicBoundingBox latLonBBox = CRS.getGeographicBoundingBox(targetCrs);
  ReferencedEnvelope bbox = new ReferencedEnvelope(new GeneralEnvelope(latLonBBox));
  Polygon geometry = JTS.toGeometry(bbox);
  double distanceTolerance = Math.max(bbox.getSpan(0), bbox.getSpan(1)) / 2E5;
  Geometry densifiedGeom = Densifier.densify(geometry, distanceTolerance);
  MathTransform mathTransform;
    CoordinateReferenceSystem sourceCRS = bbox.getCoordinateReferenceSystem();
    mathTransform = CRS.findMathTransform(sourceCRS, targetCrs);
    aovGeom = JTS.transform(densifiedGeom, mathTransform);
  } catch (Exception e) {
    throw new RuntimeException(e);
  aovGeom = JTS.toGeometry(new Envelope(envelope.getMinimum(0), envelope.getMaximum(0),
      envelope.getMinimum(1), envelope.getMaximum(1)));
aovGeom.setUserData(targetCrs);
return aovGeom;

代码示例来源:origin: geotools/geotools

@Test
public void testWrapGeometryReprojectToLatLonED50() throws Exception {
  ReferencedEnvelope world = new ReferencedEnvelope(-80, 80, -180, 180, ED50_LATLON);
  // make sure the geometry is not wrapped, but it is preserved
  ProjectionHandler handler = ProjectionHandlerFinder.getHandler(world, WGS84, true);
  // a geometry that will cross the dateline and sitting in the same area as the
  // rendering envelope (with wgs84 lon/latcoordinates)
  String wkt = "POLYGON((178 -80, 178 80, 182 80, 182 80, 178 -80))";
  Geometry g = new WKTReader().read(wkt);
  Geometry original = new WKTReader().read(wkt);
  MathTransform mt = CRS.findMathTransform(WGS84, ED50_LATLON);
  MathTransform prepared =
      handler.getRenderingTransform(CRS.findMathTransform(WGS84, ED50_LATLON));
  Geometry reprojected = JTS.transform(original, prepared);
  assertTrue(handler.requiresProcessing(g));
  Geometry preProcessed = handler.preProcess(g);
  // no cutting expected
  assertEquals(original, preProcessed);
  // post process, this should wrap the geometry and clone it
  Geometry postProcessed = handler.postProcess(prepared, reprojected);
  assertTrue(postProcessed instanceof MultiPolygon);
}

代码示例来源:origin: org.geowebcache/gwc-georss

try {
  Envelope coveredLevelEnvelope;
  coveredLevelEnvelope = JTS.transform(aggregatedGeomBounds, worldToGrid);
  Geometry bufferedEnvelopeInGridCrs;
  bufferedEnvelopeInGridCrs = JTS.toGeometry(coveredLevelEnvelope).buffer(
      ENVELOPE_BUFFER_RATIO);
  coveredLevelEnvelope = bufferedEnvelopeInGridCrs.getEnvelopeInternal();
  MathTransform gridToWorld = worldToGrid.inverse();
  Envelope bufferedEnvelope = JTS.transform(coveredLevelEnvelope, gridToWorld);
  expandedBounds = new BoundingBox(bufferedEnvelope.getMinX(),
      bufferedEnvelope.getMinY(), bufferedEnvelope.getMaxX(),
      bufferedEnvelope.getMaxY());
} catch (TransformException e) {

代码示例来源:origin: org.geotools/gt-widgets-swing-pending

GeometryFactory geofact = new GeometryFactory();
Coordinate coord = toMapCoord(event.getX(), event.getY(), env.getWidth(), env.getHeight(), rec,env);   
Point point = geofact.createPoint(coord);
    MathTransform transform = CRS.findMathTransform(sourceCRS, targetCRS);
    Geometry targetGeometry = JTS.transform( point, transform);
    coord = targetGeometry.getCoordinate();
    jtf_coord.setText("X= "+ coord.x +"  /  Y= "+coord.y);
  }catch(Exception e){

代码示例来源:origin: iandees/shp-to-osm

transform = CRS.findMathTransform(sourceCRS, targetCRS, true);
} catch (MalformedURLException e) {
  throw new ShpToOsmException("URL could not be created for input file.", e);
      String geometryType = rawGeom.getGeometryType();
        geometry = JTS.transform(rawGeom, transform);
      } catch (TransformException e) {
        throw new ShpToOsmException("Could not transform to spherical mercator.", e);
        for (int i = 0; i < geometry.getNumGeometries(); i++) {
          LineString geometryN = (LineString) geometry
              .getGeometryN(i);
          LineString outerLine = geometryN.getExteriorRing();
          if (geometryN.getNumInteriorRing() > 0) {
            Relation r = new Relation();
            r.addTag(new Tag("type", "multipolygon"));
            for (int j = 0; j < geometryN.getNumInteriorRing(); j++) {
              LineString innerLine = geometryN.getInteriorRingN(j);

代码示例来源:origin: org.geotools/gt-main

/**
 * Helper method to reproject a geometry.
 */
protected Geometry reproject( Object value, CoordinateReferenceSystem propertyCrs) {
  if ( value == null ) {
    return null;
  }
  
  if (!(value instanceof Geometry))
    throw new IllegalArgumentException("Binary geometry filter, but second expression "
        + "is not a geometry literal? (it's a " + value.getClass() + ")");
  Geometry geom = (Geometry) value;
  
  // does it make sense to proceed?
  if (geom.getUserData() == null
      || !(geom.getUserData() instanceof CoordinateReferenceSystem))
    return geom;
  try {
    // reproject
    CoordinateReferenceSystem geomCRS = (CoordinateReferenceSystem) geom.getUserData();
    Geometry transformed = JTS.transform(geom, CRS.findMathTransform(geomCRS, propertyCrs, true));
    transformed.setUserData(propertyCrs);
    
    return transformed;
  } catch(Exception e) {
    throw new RuntimeException("Could not reproject geometry " + value, e);
  }
}

代码示例来源:origin: org.geotools/gt-render

if (CRS.equalsIgnoreMetadata(geomCRS, renderingEnvelope.getCoordinateReferenceSystem())) {
  return geometry;
ReferencedEnvelope ge = new ReferencedEnvelope(geometry.getEnvelopeInternal(), geomCRS);
ReferencedEnvelope geWGS84 = ge.transform(WGS84, true);
if (validArea.contains((Envelope) geWGS84)) {
  return geometry;
Polygon envelopeGeometry = JTS.toGeometry((Envelope) envInt);
Geometry result;
try {
  result = geometry.intersection(envelopeGeometry);
} catch(Exception e1) {
  try {

代码示例来源:origin: org.locationtech.geogig/geogig-datastore

Polygon geometry = JTS.toGeometry(queryBounds);
filter = ff.intersects(ff.property(pointsType.getGeometryDescriptor().getLocalName()),
    ff.literal(geometry));
CoordinateReferenceSystem queryCrs = CRS.decode("EPSG:3857");
transformedQueryBounds = queryBounds.transform(queryCrs, true);
geometry = JTS.toGeometry(transformedQueryBounds);
geometry.setUserData(queryCrs);

代码示例来源:origin: org.locationtech.geogig/geogig-core

public Envelope getQuadCenter(Quadrant... quadrants) {
  Envelope quadBounds = getMaxBounds();
  if (quadrants != null) {
    for (Quadrant quad : quadrants) {
      quadBounds = quad.slice(quadBounds);
    }
  }
  Coordinate center = quadBounds.centre();
  Envelope nodeBounds = Node.makePrecise(new Envelope(center));
  if (!quadBounds.contains(nodeBounds)) {
    GeometryFactory gf = new GeometryFactory();
    Polygon qgeom = JTS.toGeometry(quadBounds, gf);
    ArrayList<Geometry> pointGeoms = Lists.newArrayList(gf.createPoint(center),
        JTS.toGeometry(nodeBounds, gf));
    Geometry point = gf.buildGeometry(pointGeoms);
    String msg = qgeom + " does not contain " + point;
    Assert.fail(msg);
  }
  return nodeBounds;
}

相关文章