本文整理匯總了Java中com.vividsolutions.jts.geom.Geometry.isValid方法的典型用法代碼示例。如果您正苦於以下問題:Java Geometry.isValid方法的具體用法?Java Geometry.isValid怎麽用?Java Geometry.isValid使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.vividsolutions.jts.geom.Geometry
的用法示例。
在下文中一共展示了Geometry.isValid方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: correctFeatures
import com.vividsolutions.jts.geom.Geometry; //導入方法依賴的package包/類
public static SimpleFeatureCollection correctFeatures(SimpleFeatureCollection fc){
SimpleFeatureIterator iterator=fc.features();
DefaultFeatureCollection outVector = new DefaultFeatureCollection();
while(iterator.hasNext()){
SimpleFeature sf=iterator.next();
Geometry gm=(Geometry)sf.getDefaultGeometry();
if(!gm.isValid()){
gm=JTSUtil.repair(gm);
System.out.println(gm.isValid());
}
sf.setDefaultGeometry(gm);
outVector.add(sf);
}
return fc;
}
示例2: checkGMLFootprint
import com.vividsolutions.jts.geom.Geometry; //導入方法依賴的package包/類
/**
* Check GML Footprint validity
*/
public static boolean checkGMLFootprint (String footprint)
{
try
{
Configuration configuration = new GMLConfiguration ();
Parser parser = new Parser (configuration);
Geometry geom =
(Geometry) parser.parse (new InputSource (
new StringReader (footprint)));
if (!geom.isEmpty() && !geom.isValid())
{
LOGGER.error("Wrong footprint");
return false;
}
}
catch (Exception e)
{
LOGGER.error("Error in extracted footprint: " + e.getMessage());
return false;
}
return true;
}
示例3: joinFeaures
import com.vividsolutions.jts.geom.Geometry; //導入方法依賴的package包/類
/**
*
* @param shapes
* @param shapes2
* @throws Exception
*/
private static SimpleFeatureCollection joinFeaures(SimpleFeatureSource shapes, SimpleFeatureSource shapes2) throws Exception {
SimpleFeatureCollection join =null;
SimpleFeatureType schema = shapes.getSchema();
String typeName = schema.getTypeName();
String geomName = schema.getGeometryDescriptor().getLocalName();
SimpleFeatureType schema2 = shapes2.getSchema();
String typeName2 = schema2.getTypeName();
String geomName2 = schema2.getGeometryDescriptor().getLocalName();
FilterFactory2 ff = CommonFactoryFinder.getFilterFactory2();
Query outerGeometry = new Query(typeName, Filter.INCLUDE, new String[] { geomName });
SimpleFeatureCollection outerFeatures = shapes.getFeatures(outerGeometry);
SimpleFeatureIterator iterator = outerFeatures.features();
int max = 0;
try {
while (iterator.hasNext()) {
SimpleFeature feature = iterator.next();
try {
Geometry geometry = (Geometry) feature.getDefaultGeometry();
if (!geometry.isValid()) {
// skip bad data
continue;
}
Filter innerFilter = ff.intersects(ff.property(geomName2), ff.literal(geometry));
Query innerQuery = new Query(typeName2, innerFilter, Query.NO_NAMES);
join = shapes2.getFeatures(innerQuery);
int size = join.size();
max = Math.max(max, size);
} catch (Exception skipBadData) {
}
}
} finally {
iterator.close();
}
return join;
}
示例4: updateGeoFilter
import com.vividsolutions.jts.geom.Geometry; //導入方法依賴的package包/類
/**
* Update the geo filter configuration from user supplied GeoFilter property.
*
* @param geo_filter the content of the GeoFilter property
* @throws InvalidValueException if GeoFilter is invalid
*/
private void updateGeoFilter(String geo_filter) throws InvalidValueException
{
if (geo_filter == null || geo_filter.isEmpty())
{
this.syncConf.removeConfig("geofilter_op");
this.syncConf.removeConfig("geofilter_shape");
}
else
{
Pattern pattern = Pattern.compile("(disjoint|within|contains|intersects) (.+)");
Matcher matcher = pattern.matcher(geo_filter);
if (!matcher.matches())
{
throw new InvalidValueException(SynchronizerEntitySet.GEO_FILTER, geo_filter);
}
String operator = matcher.group(1);
String wkt = matcher.group(2);
WKTReader wkt_reader = new WKTReader();
try
{
Geometry geometry = wkt_reader.read(wkt);
if (!geometry.isValid())
{
throw new InvalidValueException(SynchronizerEntitySet.GEO_FILTER, geo_filter);
}
this.syncConf.setConfig("geofilter_op", operator);
this.syncConf.setConfig("geofilter_shape", wkt);
}
catch (com.vividsolutions.jts.io.ParseException ex)
{
throw new InvalidValueException(SynchronizerEntitySet.GEO_FILTER, geo_filter);
}
}
}
示例5: validate
import com.vividsolutions.jts.geom.Geometry; //導入方法依賴的package包/類
private void validate(final Geometry geom, final List<ValidationResult> validationErrors) {
if (geom.isEmpty()) {
return;
}
if (geom instanceof GeometryCollection) {
final GeometryCollection gc = (GeometryCollection) geom;
for (int numGeom = 0; numGeom < gc.getNumGeometries(); numGeom++) {
validate(gc.getGeometryN(numGeom), validationErrors);
}
}
final ValidationResult result = new ValidationResult();
result.setWkt(geom.toText());
final List<String> messages = new ArrayList<String>();
if (!geom.isValid()) {
messages.add("Error en topología básica");
}
if (!geom.isSimple()) {
messages.add("No es una geometría simple");
}
if (repeatedPointTester.hasRepeatedPoint(geom)) {
messages.add("Se encuentran vértices repetidos");
}
if (geom instanceof Polygon) {
final Polygon polygon = (Polygon) geom;
if (CGAlgorithms.isCCW(polygon.getExteriorRing().getCoordinates())) {
messages.add("Error en orientación del polígono");
} else {
for (int numRing = 0; numRing < polygon.getNumInteriorRing(); numRing++) {
if (!CGAlgorithms.isCCW(polygon.getInteriorRingN(numRing).getCoordinates())) {
messages.add("Error en orientación del polígono en anillos interiores");
break;
}
}
}
if (!validateMinPolygonArea(geom)) {
messages.add("Error en validación mínima de area de un polígono");
}
}
if (!validateMinSegmentLength(geom)) {
messages.add("Error en validación mínima de longitud de segmento. Coordenadas");
result.setErrorsPoints(errorCoordinates);
}
if(!messages.isEmpty()) {
result.setMessages(messages);
validationErrors.add(result);
}
}