Java com.vividsolutions.jts.io.WKTReader 代码实例

・5 分钟阅读

以下是展示如何使用com.vividsolutions.jts.io.WKTReader的最佳示例。 我们使用了代码质量辨别算法从开源项目中提取出了最佳的优秀示例。

实例 1


/**
 *
 * @param wktGeometries
 * @return
 * @throws SharkKBException
 */
private List<Geometry> convertToJTSGeometries(List<String> wktGeometries) throws SharkKBException {
    List<Geometry> jtsGeometries = new ArrayList();
    WKTReader reader = new WKTReader();
    for (String wktGeom : wktGeometries) {
        try {
            Geometry tempGeom = reader.read(wktGeom);
            jtsGeometries.add(tempGeom);
        } catch (ParseException ex) {
            throw new SharkKBException("WKT parsing problem with SpatialSTSet ");
        }
    }
    return jtsGeometries;
}
 

实例 2


@Override
protected void doEvaluate(TExecutionContext context, LazyList<? extends ValueSource> inputs, ValueTarget output) {
    String wkt = inputs.get(0).getString();
    WKTReader reader = (WKTReader)context.preptimeObjectAt(READER_CONTEXT_POS);
    try {
        Geometry geometry = reader.read(wkt);
        output.putObject(geometry);
    } catch(ParseException e) {
        throw new InvalidSpatialObjectException(e.getMessage());
    }
}
 

实例 3


@BeforeClass
public static void initMockReport()
                        throws Exception {
    WKTReader wktReader = new WKTReader();
    geometrySimple = wktReader.read( GEOMETRY_SIMPLE );
    mockReport = new ResponseClippingReport( geometrySimple, true );
    geometryFailure = wktReader.read( GEOMETRY_FAILURE );
    geometryEmpty = new GeometryFactory().toGeometry( new Envelope() );
    mockEmptyReport = new ResponseClippingReport( geometryEmpty, true );
}
 

实例 4


public static Geometry readGeometry(String value) {
    WKTReader wktReader = new WKTReader();
    Geometry geo = null;
    try {
        geo = wktReader.read(value);
    } catch (ParseException e) {
        LOGGER.warn("Failed to parse geometry information.", e);
    }
    return geo;
}
 

实例 5


private com.vividsolutions.jts.geom.Geometry readGeoFromWkt(final String wkt) throws
        CatalogTransformerException {
    WKTReader reader = new WKTReader();
    try {
        return reader.read(wkt);
    } catch (ParseException e) {
        throw new CatalogTransformerException("Unable to parse WKT to Geometry.", e);
    }
}
 

实例 6


public static void main(String[] args)
    throws Exception
{
  WKTReader rdr = new WKTReader();
  Geometry[] geom = new Geometry[3];
  geom[0] = rdr.read("POLYGON (( 100 180, 100 260, 180 260, 180 180, 100 180 ))");
  geom[1] = rdr.read("POLYGON (( 80 140, 80 200, 200 200, 200 140, 80 140 ))");
  geom[2] = rdr.read("POLYGON (( 160 160, 160 240, 240 240, 240 160, 160 160 ))");
  unionUsingBuffer(geom);
}
 

实例 7


public static void main(String[] args)
    throws Exception
{
  WKTReader rdr = new WKTReader();
  LineString line1 = (LineString) (rdr.read("LINESTRING (0 0, 10 10, 20 20)"));
  showSelfIntersections(line1);
  LineString line2 = (LineString) (rdr.read("LINESTRING (0 40, 60 40, 60 0, 20 0, 20 60)"));
  showSelfIntersections(line2);
}
 

实例 8


static public Geometry geomFromWKT(String wkt) {
    WKTReader wktreader = new WKTReader();
    try {
        return wktreader.read(wkt);
    } catch (Exception e) {
        throw new IllegalArgumentException("bad wkt");
    }
}
 

实例 9


/**
 * Reads a geometry from its well known text representation, specifying an 
 * srid.
 * 
 * @param wkt The well known text of the geometry.
 * @param srid The srid of the geometry
 * 
 * @return An array of bytes representing the geometry.
 */
public static byte[] GeomFromText(String wkt, int srid) {
    if ( wkt == null ) {
        return null;
    }
    WKTReader reader = new WKTReader();
    try {
        Geometry g = reader.read( wkt );
        g.setSRID(srid);
        return toWKB( g );
    } 
    catch (ParseException e) {
        throw new RuntimeException( e );
    }
}
 
讨论
淘淘あ西西 profile image