当前位置: 首页>>代码示例>>Java>>正文


Java WKTReader类代码示例

本文整理汇总了Java中com.vividsolutions.jts.io.WKTReader的典型用法代码示例。如果您正苦于以下问题:Java WKTReader类的具体用法?Java WKTReader怎么用?Java WKTReader使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


WKTReader类属于com.vividsolutions.jts.io包,在下文中一共展示了WKTReader类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: tryCatalog

import com.vividsolutions.jts.io.WKTReader; //导入依赖的package包/类
private void tryCatalog() throws Exception {
    Connection conn = DriverManager.getConnection("jdbc:h2:~/.sumo/SUMO_DB;AUTO_SERVER=TRUE", "sa", "");
    Statement stat = conn.createStatement();
    List<File> readFiles = new ArrayList<File>();

    String sql = "SELECT * FROM CATALOGUE";
    ResultSet res = stat.executeQuery(sql);
    Geometry imageGeom = null;
    WKTReader wktr = new WKTReader();
    while (res.next()) {
        imageGeom = wktr.read(res.getString("GEOM"));
        String fileName = res.getString("IMAGENAME");
        File f = new File(fileName);
        readFiles.add(f);
    }
    jList1.removeAll();
    jList1.setListData(readFiles.toArray());
}
 
开发者ID:ec-europa,项目名称:sumo,代码行数:19,代码来源:BatchAnalysisGUI.java

示例2: createPolygon

import com.vividsolutions.jts.io.WKTReader; //导入依赖的package包/类
/**
 *
 * @param xs
 * @return
 * @throws ParseException
 */
public static Polygon createPolygon(double[]...xs) throws ParseException{
	StringBuilder builder =new StringBuilder("POLYGON((");

	for(int i=0;i<xs.length;i++){
		double x[]=xs[i];
		if(i<(xs.length-1))
			builder=builder.append(x[0]).append(" ").append(x[1]).append(",");
		else
			builder=builder.append(x[0]).append(" ").append(x[1]).append("))");
	}
	Polygon imageP = (Polygon) new WKTReader().read(builder.toString());
	/*Coordinate[]cs=new Coordinate[xs.length];
	for(int i=0;i<xs.length;i++){
		cs[i]=new Coordinate(xs[i][0],xs[i][1]);
	}
	GeometryFactory factor=new GeometryFactory();
	Polygon imageP=factor.createPolygon(cs);*/

	return imageP;
}
 
开发者ID:ec-europa,项目名称:sumo,代码行数:27,代码来源:PolygonOp.java

示例3: getFrame

import com.vividsolutions.jts.io.WKTReader; //导入依赖的package包/类
public static Geometry getFrame(GeoImageReader gir) throws GeoTransformException{
    try {
        GeoTransform gt = gir.getGeoTransform();
        double[] x0;
        double[] x1;
        double[] x2;
        double[] x3;
        x0 = gt.getGeoFromPixel(-50, -50);
        x2 = gt.getGeoFromPixel(50 + gir.getWidth(), 50 + gir.getHeight());
        x3 = gt.getGeoFromPixel(50 + gir.getWidth(), -50);
        x1 = gt.getGeoFromPixel(-50, 50 + gir.getHeight());
        return new WKTReader().read("POLYGON((" + x0[0] + " " + x0[1] + "," + x1[0] + " " + x1[1] + "," + x2[0] + " " + x2[1] + "," + x3[0] + " " + x3[1] + "," + x0[0] + " " + x0[1] + "" + "))");
    } catch (ParseException ex) {
    	logger.error(ex.getMessage(),ex);
    }
    return null;
}
 
开发者ID:ec-europa,项目名称:sumo,代码行数:18,代码来源:GeometryExtractor.java

示例4: doSelect

import com.vividsolutions.jts.io.WKTReader; //导入依赖的package包/类
private void doSelect() {
    if (whereClause != null) {
        try {
            Connection conn = DriverManager.getConnection("jdbc:h2:~/.sumo/VectorData;AUTO_SERVER=TRUE", "sa", "");
            Statement stat = conn.createStatement();
            ResultSet rs = stat.executeQuery("SELECT * FROM \"" + glayer.getName() + "\" WHERE " + whereClause);
            WKTReader wkt = new WKTReader();
            String[] schema = glayer.getSchema();
            //TODO:schema type problem check!!
            //String[] types = glayer.getSchemaTypes();
            glayer.clear();
            while (rs.next()) {
                Geometry geom = wkt.read(rs.getString("geom"));
                AttributesGeometry att = new AttributesGeometry(schema);
                for (String key : schema) {
                    att.set(key, rs.getString(key));
                }
                glayer.put(geom, att);
            }
        } catch (Exception ex) {
            logger.error(ex.getMessage(),ex);
        }
        whereClause = null;
    }
}
 
开发者ID:ec-europa,项目名称:sumo,代码行数:26,代码来源:SelectableVectorLayer.java

示例5: checkJTSFootprint

import com.vividsolutions.jts.io.WKTReader; //导入依赖的package包/类
/**
 * Check JTS Footprint validity
 */
public static boolean checkJTSFootprint (String footprint)
{
   try
   {
      WKTReader wkt = new WKTReader();
      Geometry geom = wkt.read(footprint);
      IsValidOp vaildOp = new IsValidOp(geom);
      TopologyValidationError err = vaildOp.getValidationError();
      if (err != null)
      {
         throw new IllegalParameterException(err.getMessage());
      }
      return true;
   }
   catch (Exception e)
   {
      LOGGER.error("JTS Footprint error : " + e.getMessage());
      return false;
   }
}
 
开发者ID:SentinelDataHub,项目名称:dhus-core,代码行数:24,代码来源:ProcessingUtils.java

示例6: testCompileArcWithTolerance

import com.vividsolutions.jts.io.WKTReader; //导入依赖的package包/类
@Test
public void testCompileArcWithTolerance() {
  WKTReader reader = new WKTReader();
  try {
    Geometry g1 = reader
        .read("LINESTRING (601103.3340069023 129288.05055561525, 601102.0842804064 129856.67611130093, 601320.7864172085 129316.79426502353, 601323.263544294 129847.90736367383)");
    Geometry g2 = reader
        .read("LINESTRING (601323.2858702005 129847.92802582885, 601824.4261951016 129860.42529078897, 601968.144742143 129494.25542745732, 601806.9300241574 129236.81176927875, 601447.0087933057 129430.51937616068, 601422.0142633856 129672.9663163871, 601549.4863659788 129830.43185488468)");

    ILineString line1 = (ILineString) AdapterFactory.toGM_Object(g1);
    ILineString line2 = (ILineString) AdapterFactory.toGM_Object(g2);
    List<ILineString> list = new ArrayList<ILineString>();
    list.add(line1);
    list.add(line2);
    ILineString result = Operateurs.compileArcs(list, 1.0);
    Assert.assertNotNull(result);
  } catch (Exception e) {
    e.printStackTrace();
  }
}
 
开发者ID:IGNF,项目名称:geoxygene,代码行数:21,代码来源:OperateursTest.java

示例7: testUnionWithTolerance

import com.vividsolutions.jts.io.WKTReader; //导入依赖的package包/类
@Test
public void testUnionWithTolerance() {
  WKTReader reader = new WKTReader();
  try {
    Geometry g1 = reader
        .read("LINESTRING (601103.3340069023 129288.05055561525, 601102.0842804064 129856.67611130093, 601320.7864172085 129316.79426502353, 601323.263544294 129847.90736367383)");
    Geometry g2 = reader
        .read("LINESTRING (601323.2858702005 129847.92802582885, 601824.4261951016 129860.42529078897, 601968.144742143 129494.25542745732, 601806.9300241574 129236.81176927875, 601447.0087933057 129430.51937616068, 601422.0142633856 129672.9663163871, 601549.4863659788 129830.43185488468)");

    ILineString line1 = (ILineString) AdapterFactory.toGM_Object(g1);
    ILineString line2 = (ILineString) AdapterFactory.toGM_Object(g2);
    List<ILineString> list = new ArrayList<ILineString>();
    list.add(line1);
    list.add(line2);
    ILineString result = Operateurs.union(list, 1.0);
    if (result.equals(line1)) {
      Assert.fail();
    }
  } catch (Exception e) {
    e.printStackTrace();
  }
}
 
开发者ID:IGNF,项目名称:geoxygene,代码行数:23,代码来源:OperateursTest.java

示例8: getGeoObjs

import com.vividsolutions.jts.io.WKTReader; //导入依赖的package包/类
private DBObject[] getGeoObjs(final Collection<IndexingExpr> geoFilters) {
    final List<DBObject> objs = new ArrayList<>();
    geoFilters.forEach(filter -> {
        final GeoPolicy policy = GeoPolicy.fromURI(filter.getFunction());
        final WKTReader reader = new WKTReader();
        final String geoStr = ((Value) filter.getArguments()[0]).stringValue();
        try {
            //This method is what is used in the GeoIndexer.
            final Geometry geo = reader.read(geoStr);
            objs.add(getGeoObject(geo, policy));
        } catch (final GeoTemporalIndexException | UnsupportedOperationException | ParseException e) {
            LOG.error("Unable to parse '" + geoStr + "'.", e);
        }
    });
    return objs.toArray(new DBObject[]{});
}
 
开发者ID:apache,项目名称:incubator-rya,代码行数:17,代码来源:GeoTemporalMongoDBStorageStrategy.java

示例9: serialize

import com.vividsolutions.jts.io.WKTReader; //导入依赖的package包/类
@Override
public DBObject serialize(final RyaStatement ryaStatement) {
    // if the object is wkt, then try to index it
    // write the statement data to the fields
    try {
        final Statement statement = RyaToRdfConversions.convertStatement(ryaStatement);
        final Geometry geo = (new WKTReader()).read(GeoParseUtils.getWellKnownText(statement));
        if(geo == null) {
            LOG.error("Failed to parse geo statement: " + statement.toString());
            return null;
        }
        final BasicDBObject base = (BasicDBObject) super.serialize(ryaStatement);
        if (geo.getNumPoints() > 1) {
            base.append(GEO, getCorrespondingPoints(geo));
        } else {
            base.append(GEO, getDBPoint(geo));
        }
        return base;
    } catch(final ParseException e) {
        LOG.error("Could not create geometry for statement " + ryaStatement, e);
        return null;
    }
}
 
开发者ID:apache,项目名称:incubator-rya,代码行数:24,代码来源:GeoMongoDBStorageStrategy.java

示例10: getGeometry

import com.vividsolutions.jts.io.WKTReader; //导入依赖的package包/类
/**
 * Parse GML/wkt literal to Geometry
 *
 * @param statement
 * @return
 * @throws ParseException
 * @throws ParserConfigurationException
 * @throws SAXException
 * @throws IOException
 */
public static Geometry getGeometry(final Statement statement, GmlToGeometryParser gmlToGeometryParser) throws ParseException {
    // handle GML or WKT
    final Literal lit = getLiteral(statement);
    if (GeoConstants.XMLSCHEMA_OGC_WKT.equals(lit.getDatatype())) {
        final String wkt = lit.getLabel().toString();
        return (new WKTReader()).read(wkt);
    } else if (GeoConstants.XMLSCHEMA_OGC_GML.equals(lit.getDatatype())) {
        final String gml = lit.getLabel().toString();
        try {
            return getGeometryGml(gml, gmlToGeometryParser);
        } catch (IOException | SAXException | ParserConfigurationException e) {
            throw new ParseException(e);
        }
    } else {
        throw new ParseException("Literal is unknown geo type, expecting WKT or GML: " + statement.toString());
    }
}
 
开发者ID:apache,项目名称:incubator-rya,代码行数:28,代码来源:GeoParseUtils.java

示例11: testSimplifyLevel4

import com.vividsolutions.jts.io.WKTReader; //导入依赖的package包/类
@Test
@Ignore
public void testSimplifyLevel4() throws Exception {
	JtsSpatialContext ctx = new JtsSpatialContext(false);
	SampleDataReader sampleDataReader = new SampleDataReader(level4Resource.getInputStream());
	PrintWriter printWriter = new PrintWriter(new BufferedWriter(new FileWriter("level4_simplified.txt")));
	WKTReader wktreader = new WKTReader();
	WKTWriter wktwriter = new WKTWriter();

	while(sampleDataReader.hasNext()) {
		SampleData sampleData = sampleDataReader.next();

		Geometry geom = wktreader.read(sampleData.shape);
		if(!geom.isValid()) {
			logger.warn(sampleData.name + " is not valid");
		}

		printWriter.print(sampleData.id +"\t" + sampleData.code + "\t" + sampleData.name +"\t" + wktwriter.write(TopologyPreservingSimplifier.simplify(geom,0.2)) + "\n");

	}
	printWriter.flush();
}
 
开发者ID:RBGKew,项目名称:eMonocot,代码行数:23,代码来源:JtsGeometryTest.java

示例12: testGetLineSegment

import com.vividsolutions.jts.io.WKTReader; //导入依赖的package包/类
@Test
public void testGetLineSegment() throws Exception {
    LineString string = (LineString) new WKTReader().read("LINESTRING(0 1, 2 3, 4 5, 6 7)");

    LineSegment result = GeometryUtils.getLineSegment(string, 0);
    assertEquals(0, result.p0.x, EXACT_PRECISION);
    assertEquals(1, result.p0.y, EXACT_PRECISION);
    assertEquals(2, result.p1.x, EXACT_PRECISION);
    assertEquals(3, result.p1.y, EXACT_PRECISION);

    result = GeometryUtils.getLineSegment(string, 1);
    assertEquals(2, result.p0.x, EXACT_PRECISION);
    assertEquals(3, result.p0.y, EXACT_PRECISION);
    assertEquals(4, result.p1.x, EXACT_PRECISION);
    assertEquals(5, result.p1.y, EXACT_PRECISION);
}
 
开发者ID:grimsa,项目名称:polysplit,代码行数:17,代码来源:GeometryUtilsTest.java

示例13: testSimplifyLevel4

import com.vividsolutions.jts.io.WKTReader; //导入依赖的package包/类
@Test
@Ignore
public void testSimplifyLevel4() throws Exception {
	JtsSpatialContextFactory factory = new JtsSpatialContextFactory();
	factory.geo = false;
	JtsSpatialContext ctx = new JtsSpatialContext(factory);
	SampleDataReader sampleDataReader = new SampleDataReader(level4Resource.getInputStream());
	PrintWriter printWriter = new PrintWriter(new BufferedWriter(new FileWriter("level4_simplified.txt")));
	WKTReader wktreader = new WKTReader();
	WKTWriter wktwriter = new WKTWriter();

	while(sampleDataReader.hasNext()) {
		SampleData sampleData = sampleDataReader.next();

		Geometry geom = wktreader.read(sampleData.shape);
		if(!geom.isValid()) {
			logger.warn(sampleData.name + " is not valid");
		}

		printWriter.print(sampleData.id +"\t" + sampleData.code + "\t" + sampleData.name +"\t" + wktwriter.write(TopologyPreservingSimplifier.simplify(geom,0.2)) + "\n");

	}
	printWriter.flush();
}
 
开发者ID:RBGKew,项目名称:powop,代码行数:25,代码来源:JtsGeometryTest.java

示例14: clipGeometry

import com.vividsolutions.jts.io.WKTReader; //导入依赖的package包/类
/**
 * Clip geometry according to buffer given at construct time. This method
 * can be overridden to change clipping behavior. See also
 * {@link #clipCovers(Geometry)}.
 *
 * @param geometry
 * @return
 */
protected Geometry clipGeometry(Geometry geometry) {
    try {
        Geometry original = geometry;
        geometry = clipGeometry.intersection(original);

        // some times a intersection is returned as an empty geometry.
        // going via wkt fixes the problem.
        if (geometry.isEmpty() && original.intersects(clipGeometry)) {
            Geometry originalViaWkt = new WKTReader().read(original.toText());
            geometry = clipGeometry.intersection(originalViaWkt);
        }

        return geometry;
    } catch (TopologyException e) {
        // could not intersect. original geometry will be used instead.
        return geometry;
    } catch (ParseException e1) {
        // could not encode/decode WKT. original geometry will be used
        // instead.
        return geometry;
    }
}
 
开发者ID:stefan0722,项目名称:gs-mvt,代码行数:31,代码来源:VectorTileEncoder.java

示例15: wktToGeometry

import com.vividsolutions.jts.io.WKTReader; //导入依赖的package包/类
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;
    }
 
开发者ID:AuScope,项目名称:IGSN,代码行数:19,代码来源:SpatialUtilities.java


注:本文中的com.vividsolutions.jts.io.WKTReader类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。