mil.nga.sf.util.GeometryUtils Java Examples

The following examples show how to use mil.nga.sf.util.GeometryUtils. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: GoogleMapShapeConverter.java    From geopackage-android-map with MIT License 6 votes vote down vote up
/**
 * When the simplify tolerance is set, simplify the points to a similar
 * curve with fewer points.
 *
 * @param points ordered points
 * @return simplified points
 */
private List<Point> simplifyPoints(List<Point> points) {

    List<Point> simplifiedPoints = null;
    if (simplifyTolerance != null) {

        // Reproject to web mercator if not in meters
        if (projection != null && !projection.isUnit(Units.METRES)) {
            points = toWebMercator.transform(points);
        }

        // Simplify the points
        simplifiedPoints = GeometryUtils.simplifyPoints(points,
                simplifyTolerance);

        // Reproject back to the original projection
        if (projection != null && !projection.isUnit(Units.METRES)) {
            simplifiedPoints = fromWebMercator.transform(simplifiedPoints);
        }
    } else {
        simplifiedPoints = points;
    }

    return simplifiedPoints;
}
 
Example #2
Source File: ObservationTask.java    From mage-android with Apache License 2.0 6 votes vote down vote up
@Override
protected Void doInBackground(Observation... observations) {
    for (Observation o : observations) {
        boolean passesFilter = true;
        for (Filter filter : filters) {
            passesFilter = filter.passesFilter(o);
            if (!passesFilter) {
                break;
            }
        }

        if (passesFilter) {
            Geometry geometry = o.getGeometry();
            Point centroid = GeometryUtils.getCentroid(geometry);
            MarkerOptions options = new MarkerOptions().position(new LatLng(centroid.getY(), centroid.getX())).icon(ObservationBitmapFactory.bitmapDescriptor(context, o));
            publishProgress(new Pair<>(options, o));
        }
    }

    return null;
}
 
Example #3
Source File: ObservationLoadTask.java    From mage-android with Apache License 2.0 6 votes vote down vote up
@Override
protected Void doInBackground(Void... params ) {
    CloseableIterator<Observation> iterator = null;
    try {
        iterator = iterator();
        while (iterator.hasNext() && !isCancelled()) {
            Observation o = iterator.current();
            Geometry geometry = o.getGeometry();
            Point centroid = GeometryUtils.getCentroid(geometry);
            MarkerOptions options = new MarkerOptions().position(new LatLng(centroid.getY(), centroid.getX())).icon(ObservationBitmapFactory.bitmapDescriptor(context, o));

            publishProgress(new Pair<>(options, o));
        }

    } catch (SQLException e) {
        e.printStackTrace();
    } finally {
        if (iterator != null) {
            iterator.closeQuietly();
        }
    }

    return null;
}
 
Example #4
Source File: FeatureStylesUtils.java    From geopackage-java with MIT License 5 votes vote down vote up
private static List<GeometryType> getAllChildTypes(
		GeometryType geometryType) {

	List<GeometryType> allChildTypes = new ArrayList<>();

	List<GeometryType> childTypes = GeometryUtils.childTypes(geometryType);
	allChildTypes.addAll(childTypes);

	for (GeometryType childType : childTypes) {
		allChildTypes.addAll(getAllChildTypes(childType));
	}

	return allChildTypes;
}
 
Example #5
Source File: FeatureStylesUtils.java    From geopackage-java with MIT License 5 votes vote down vote up
private static void validateRowIcons(FeatureTableStyles featureTableStyles,
		FeatureRow featureRow, IconRow tableIconDefault,
		Map<GeometryType, IconRow> geometryTypeTableIcons,
		Map<Long, Map<GeometryType, IconRow>> featureResultsIcons) {

	GeometryType geometryType = featureRow.getGeometryType();

	validateRowIcons(featureTableStyles, featureRow, null, tableIconDefault,
			geometryTypeTableIcons, featureResultsIcons);

	if (geometryType != null) {

		List<GeometryType> geometryTypes = GeometryUtils
				.parentHierarchy(geometryType);
		for (GeometryType parentGeometryType : geometryTypes) {
			validateRowIcons(featureTableStyles, featureRow,
					parentGeometryType, tableIconDefault,
					geometryTypeTableIcons, featureResultsIcons);
		}

		List<GeometryType> childTypes = getAllChildTypes(geometryType);
		for (GeometryType childGeometryType : childTypes) {
			validateRowIcons(featureTableStyles, featureRow,
					childGeometryType, tableIconDefault,
					geometryTypeTableIcons, featureResultsIcons);
		}
	}

}
 
Example #6
Source File: FeatureStylesUtils.java    From geopackage-java with MIT License 5 votes vote down vote up
private static void validateRowStyles(FeatureTableStyles featureTableStyles,
		FeatureRow featureRow, StyleRow tableStyleDefault,
		Map<GeometryType, StyleRow> geometryTypeTableStyles,
		Map<Long, Map<GeometryType, StyleRow>> featureResultsStyles) {

	GeometryType geometryType = featureRow.getGeometryType();

	validateRowStyles(featureTableStyles, featureRow, null,
			tableStyleDefault, geometryTypeTableStyles,
			featureResultsStyles);

	if (geometryType != null) {

		List<GeometryType> geometryTypes = GeometryUtils
				.parentHierarchy(geometryType);
		for (GeometryType parentGeometryType : geometryTypes) {
			validateRowStyles(featureTableStyles, featureRow,
					parentGeometryType, tableStyleDefault,
					geometryTypeTableStyles, featureResultsStyles);
		}

		List<GeometryType> childTypes = getAllChildTypes(geometryType);
		for (GeometryType childGeometryType : childTypes) {
			validateRowStyles(featureTableStyles, featureRow,
					childGeometryType, tableStyleDefault,
					geometryTypeTableStyles, featureResultsStyles);
		}
	}

}
 
Example #7
Source File: FeatureTiles.java    From geopackage-java with MIT License 5 votes vote down vote up
/**
 * When the simplify tolerance is set, simplify the points to a similar
 * curve with fewer points.
 * 
 * @param simplifyTolerance
 *            simplify tolerance in meters
 * @param points
 *            ordered points
 * @return simplified points
 * @since 2.0.0
 */
protected List<Point> simplifyPoints(double simplifyTolerance,
		List<Point> points) {

	List<Point> simplifiedPoints = null;
	if (simplifyGeometries) {

		// Reproject to web mercator if not in meters
		if (projection != null && !projection.isUnit(Units.METRES)) {
			ProjectionTransform toWebMercator = projection
					.getTransformation(WEB_MERCATOR_PROJECTION);
			points = toWebMercator.transform(points);
		}

		// Simplify the points
		simplifiedPoints = GeometryUtils.simplifyPoints(points,
				simplifyTolerance);

		// Reproject back to the original projection
		if (projection != null && !projection.isUnit(Units.METRES)) {
			ProjectionTransform fromWebMercator = WEB_MERCATOR_PROJECTION
					.getTransformation(projection);
			simplifiedPoints = fromWebMercator.transform(simplifiedPoints);
		}
	} else {
		simplifiedPoints = points;
	}

	return simplifiedPoints;
}
 
Example #8
Source File: Styles.java    From geopackage-java with MIT License 5 votes vote down vote up
/**
 * Get the style for the geometry type
 * 
 * @param geometryType
 *            geometry type
 * @return style
 */
public StyleRow getStyle(GeometryType geometryType) {

	StyleRow styleRow = null;

	if (geometryType != null && !styles.isEmpty()) {
		List<GeometryType> geometryTypes = GeometryUtils
				.parentHierarchy(geometryType);
		geometryTypes.add(0, geometryType);
		for (GeometryType type : geometryTypes) {
			styleRow = styles.get(type);
			if (styleRow != null) {
				break;
			}
		}
	}

	if (styleRow == null) {
		styleRow = defaultStyle;
	}

	if (styleRow == null && geometryType == null && styles.size() == 1) {
		styleRow = styles.values().iterator().next();
	}

	return styleRow;
}
 
Example #9
Source File: Icons.java    From geopackage-java with MIT License 5 votes vote down vote up
/**
 * Get the icon for the geometry type
 * 
 * @param geometryType
 *            geometry type
 * @return icon
 */
public IconRow getIcon(GeometryType geometryType) {

	IconRow iconRow = null;

	if (geometryType != null && !icons.isEmpty()) {
		List<GeometryType> geometryTypes = GeometryUtils
				.parentHierarchy(geometryType);
		geometryTypes.add(0, geometryType);
		for (GeometryType type : geometryTypes) {
			iconRow = icons.get(type);
			if (iconRow != null) {
				break;
			}
		}
	}

	if (iconRow == null) {
		iconRow = defaultIcon;
	}

	if (iconRow == null && geometryType == null && icons.size() == 1) {
		iconRow = icons.values().iterator().next();
	}

	return iconRow;
}
 
Example #10
Source File: MapObservationManager.java    From mage-android with Apache License 2.0 5 votes vote down vote up
/**
 * Add an observation to the map as a marker or shape
 *
 * @param observation observation
 * @param markerOptions marker options
 * @param visible     visible state
 * @return map observation
 */
public MapObservation addToMap(Observation observation, MarkerOptions markerOptions, boolean visible) {

    MapObservation observationShape = null;

    Geometry geometry = observation.getGeometry();

    if (geometry.getGeometryType() == GeometryType.POINT) {
        Point point = GeometryUtils.getCentroid(geometry);
        if(markerOptions == null) {
            markerOptions = getMarkerOptions(observation, visible);
            markerOptions.position(new LatLng(point.getY(), point.getX()));
        }
        Marker marker = map.addMarker(markerOptions);

        observationShape = new MapMarkerObservation(observation, marker);
    } else {

        GoogleMapShapeConverter shapeConverter = new GoogleMapShapeConverter();
        GoogleMapShape shape = shapeConverter.toShape(geometry);
        prepareShapeOptions(observation, shape, visible);
        GoogleMapShape mapShape = GoogleMapShapeConverter.addShapeToMap(map, shape);

        observationShape = MapShapeObservation.create(observation, mapShape);
    }

    return observationShape;
}
 
Example #11
Source File: LocationTask.java    From mage-android with Apache License 2.0 5 votes vote down vote up
@Override
protected Void doInBackground(Location... locations) {        
	for (Location location : locations) {
        User user = location.getUser();
        if (user == null) {
            continue;
        }

        boolean passesFilter = true;
        for (Filter filter : filters) {
            passesFilter = filter.passesFilter(location);
            if (!passesFilter) {
                break;
            }
        }

        if (passesFilter) {
            Point point = GeometryUtils.getCentroid(location.getGeometry());
            LatLng latLng = new LatLng(point.getY(), point.getX());
            MarkerOptions options = new MarkerOptions().position(latLng).icon(LocationBitmapFactory.bitmapDescriptor(context, location, user));

            publishProgress(new Pair<>(options, new Pair<>(location, user)));
        }
    }
    
    return null;
}
 
Example #12
Source File: ObservationMarkerCollection.java    From mage-android with Apache License 2.0 5 votes vote down vote up
@Override
public boolean onMarkerClick(Marker marker) {

    boolean handled = false;

    Observation observation = mapObservations.getMarkerObservation(marker.getId());
    if (observation != null) {
        final Geometry g = observation.getGeometry();
        if (g != null) {
            Point point = GeometryUtils.getCentroid(g);
            LatLng latLng = new LatLng(point.getY(), point.getX());
            Float accuracy = observation.getAccuracy();
            if (accuracy != null) {
                try {
                    if (observationAccuracyCircle != null) {
                        observationAccuracyCircle.second.remove();
                    }

                    Circle circle = map.addCircle(new CircleOptions()
                        .center(latLng)
                        .radius(accuracy)
                        .fillColor(context.getResources().getColor(R.color.accuracy_circle_fill))
                        .strokeColor(context.getResources().getColor(R.color.accuracy_circle_stroke))
                        .strokeWidth(2.0f));

                    observationAccuracyCircle = new Pair<>(observation.getRemoteId(), circle);
                } catch (NumberFormatException nfe) {
                    Log.e(LOG_NAME, "Problem adding accuracy circle to the map.", nfe);
                }
            }
        }

        map.setInfoWindowAdapter(infoWindowAdapter);
        marker.showInfoWindow();
        handled = true;
    }

    return handled;
}
 
Example #13
Source File: LocationLoadTask.java    From mage-android with Apache License 2.0 5 votes vote down vote up
@Override
protected Void doInBackground(Void... params) {
	CloseableIterator<Location> iterator = null;
	try {
		iterator = iterator();
		while (iterator.hasNext() && !isCancelled()) {
			Location location = iterator.current();
			User user = location.getUser();
			if (user == null) {
				continue;
			}

			Point point = GeometryUtils.getCentroid(location.getGeometry());
			LatLng latLng = new LatLng(point.getY(), point.getX());
			MarkerOptions options = new MarkerOptions().position(latLng).icon(LocationBitmapFactory.bitmapDescriptor(context, location, user));

			publishProgress(new Pair<>(options, new Pair<>(location, user)));
		}
	} catch (SQLException e) {
		e.printStackTrace();
	} finally {
		if (iterator != null) {
			iterator.closeQuietly();
		}
	}

	return null;
}
 
Example #14
Source File: FeatureStylesUtils.java    From geopackage-android with MIT License 5 votes vote down vote up
private static void validateRowIcons(FeatureTableStyles featureTableStyles,
                                     FeatureRow featureRow, IconRow tableIconDefault,
                                     Map<GeometryType, IconRow> geometryTypeTableIcons,
                                     Map<Long, Map<GeometryType, IconRow>> featureResultsIcons) {

    GeometryType geometryType = featureRow.getGeometryType();

    validateRowIcons(featureTableStyles, featureRow, null,
            tableIconDefault, geometryTypeTableIcons, featureResultsIcons);

    if (geometryType != null) {

        List<GeometryType> geometryTypes = GeometryUtils
                .parentHierarchy(geometryType);
        for (GeometryType parentGeometryType : geometryTypes) {
            validateRowIcons(featureTableStyles, featureRow,
                    parentGeometryType, tableIconDefault,
                    geometryTypeTableIcons, featureResultsIcons);
        }

        List<GeometryType> childTypes = getAllChildTypes(geometryType);
        for (GeometryType childGeometryType : childTypes) {
            validateRowIcons(featureTableStyles, featureRow,
                    childGeometryType, tableIconDefault,
                    geometryTypeTableIcons, featureResultsIcons);
        }
    }

}
 
Example #15
Source File: FeatureStylesUtils.java    From geopackage-android with MIT License 5 votes vote down vote up
private static void validateRowStyles(
        FeatureTableStyles featureTableStyles, FeatureRow featureRow,
        StyleRow tableStyleDefault,
        Map<GeometryType, StyleRow> geometryTypeTableStyles,
        Map<Long, Map<GeometryType, StyleRow>> featureResultsStyles) {

    GeometryType geometryType = featureRow.getGeometryType();

    validateRowStyles(featureTableStyles, featureRow, null,
            tableStyleDefault, geometryTypeTableStyles,
            featureResultsStyles);

    if (geometryType != null) {

        List<GeometryType> geometryTypes = GeometryUtils
                .parentHierarchy(geometryType);
        for (GeometryType parentGeometryType : geometryTypes) {
            validateRowStyles(featureTableStyles, featureRow,
                    parentGeometryType, tableStyleDefault,
                    geometryTypeTableStyles, featureResultsStyles);
        }

        List<GeometryType> childTypes = getAllChildTypes(geometryType);
        for (GeometryType childGeometryType : childTypes) {
            validateRowStyles(featureTableStyles, featureRow,
                    childGeometryType, tableStyleDefault,
                    geometryTypeTableStyles, featureResultsStyles);
        }
    }

}
 
Example #16
Source File: FeatureTiles.java    From geopackage-android with MIT License 5 votes vote down vote up
/**
 * When the simplify tolerance is set, simplify the points to a similar
 * curve with fewer points.
 *
 * @param simplifyTolerance simplify tolerance in meters
 * @param points            ordered points
 * @return simplified points
 * @since 2.0.0
 */
protected List<Point> simplifyPoints(double simplifyTolerance,
                                     List<Point> points) {

    List<Point> simplifiedPoints = null;
    if (simplifyGeometries) {

        // Reproject to web mercator if not in meters
        if (projection != null && !projection.isUnit(Units.METRES)) {
            ProjectionTransform toWebMercator = projection
                    .getTransformation(WEB_MERCATOR_PROJECTION);
            points = toWebMercator.transform(points);
        }

        // Simplify the points
        simplifiedPoints = GeometryUtils.simplifyPoints(points,
                simplifyTolerance);

        // Reproject back to the original projection
        if (projection != null && !projection.isUnit(Units.METRES)) {
            ProjectionTransform fromWebMercator = WEB_MERCATOR_PROJECTION
                    .getTransformation(projection);
            simplifiedPoints = fromWebMercator.transform(simplifiedPoints);
        }
    } else {
        simplifiedPoints = points;
    }

    return simplifiedPoints;
}
 
Example #17
Source File: Styles.java    From geopackage-android with MIT License 5 votes vote down vote up
/**
 * Get the style for the geometry type
 *
 * @param geometryType geometry type
 * @return style
 */
public StyleRow getStyle(GeometryType geometryType) {

    StyleRow styleRow = null;

    if (geometryType != null && !styles.isEmpty()) {
        List<GeometryType> geometryTypes = GeometryUtils
                .parentHierarchy(geometryType);
        geometryTypes.add(0, geometryType);
        for (GeometryType type : geometryTypes) {
            styleRow = styles.get(type);
            if (styleRow != null) {
                break;
            }
        }
    }

    if (styleRow == null) {
        styleRow = defaultStyle;
    }

    if (styleRow == null && geometryType == null && styles.size() == 1) {
        styleRow = styles.values().iterator().next();
    }

    return styleRow;
}
 
Example #18
Source File: Icons.java    From geopackage-android with MIT License 5 votes vote down vote up
/**
 * Get the icon for the geometry type
 *
 * @param geometryType geometry type
 * @return icon
 */
public IconRow getIcon(GeometryType geometryType) {

    IconRow iconRow = null;

    if (geometryType != null && !icons.isEmpty()) {
        List<GeometryType> geometryTypes = GeometryUtils
                .parentHierarchy(geometryType);
        geometryTypes.add(0, geometryType);
        for (GeometryType type : geometryTypes) {
            iconRow = icons.get(type);
            if (iconRow != null) {
                break;
            }
        }
    }

    if (iconRow == null) {
        iconRow = defaultIcon;
    }

    if (iconRow == null && geometryType == null && icons.size() == 1) {
        iconRow = icons.values().iterator().next();
    }

    return iconRow;
}
 
Example #19
Source File: ObservationClusterCollection.java    From mage-android with Apache License 2.0 4 votes vote down vote up
@Override
public LatLng getPosition() {
    Point point = GeometryUtils.getCentroid(observation.getGeometry());
    return new LatLng(point.getY(), point.getX());
}
 
Example #20
Source File: LocationMarkerCollection.java    From mage-android with Apache License 2.0 4 votes vote down vote up
@Override
public boolean onMarkerClick(Marker marker) {
	Pair<Location, User> pair = markerIdToPair.get(marker.getId());
	if (pair == null) {
		return false;
	}

	Location location = pair.first;
	User user = pair.second;

	final Geometry g = location.getGeometry();
	if (g != null) {
		Point point = GeometryUtils.getCentroid(g);
		LatLng latLng = new LatLng(point.getY(), point.getX());
		LocationProperty accuracyProperty = location.getPropertiesMap().get("accuracy");
		if (accuracyProperty != null && !accuracyProperty.getValue().toString().trim().isEmpty()) {
			try {
				float accuracy = Float.parseFloat(accuracyProperty.getValue().toString());
				if (clickedAccuracyCircle != null) {
					clickedAccuracyCircle.remove();
				}

				int color = LocationBitmapFactory.locationColor(context, location);
				clickedAccuracyCircle = map.addCircle(new CircleOptions()
						.center(latLng)
						.radius(accuracy)
						.fillColor(ColorUtils.setAlphaComponent(color, (int) (256 * .20)))
						.strokeColor(ColorUtils.setAlphaComponent(color, (int) (256 * .87)))
						.strokeWidth(2.0f));
				clickedAccuracyCircleUserId = user.getId();
			} catch (NumberFormatException nfe) {
				Log.e(LOG_NAME, "Problem adding accuracy circle to the map.", nfe);
			}
		}
	}

	map.setInfoWindowAdapter(infoWindowAdapter);
	// make sure to set the Anchor after this call as well, because the size of the icon might have changed
	marker.setIcon(LocationBitmapFactory.bitmapDescriptor(context, location, user));
	marker.setAnchor(0.5f, 1.0f);
	marker.showInfoWindow();
	return true;
}
 
Example #21
Source File: ObservationLocation.java    From mage-android with Apache License 2.0 4 votes vote down vote up
/**
 * Get a geometry envelope that includes the entire geometry
 *
 * @return geometry envelope
 */
private GeometryEnvelope getGeometryEnvelope() {
    Geometry geometryCopy = geometry.copy();
    GeometryUtils.minimizeGeometry(geometryCopy, ProjectionConstants.WGS84_HALF_WORLD_LON_WIDTH);
    return GeometryEnvelopeBuilder.buildEnvelope(geometryCopy);
}
 
Example #22
Source File: FeatureStylesUtils.java    From geopackage-android with MIT License 3 votes vote down vote up
private static List<GeometryType> getAllChildTypes(GeometryType geometryType) {

        List<GeometryType> allChildTypes = new ArrayList<>();

        List<GeometryType> childTypes = GeometryUtils.childTypes(geometryType);
        allChildTypes.addAll(childTypes);

        for (GeometryType childType : childTypes) {
            allChildTypes.addAll(getAllChildTypes(childType));
        }

        return allChildTypes;
    }
 
Example #23
Source File: ObservationLocation.java    From mage-android with Apache License 2.0 2 votes vote down vote up
/**
 * Get the geometry centroid
 *
 * @return centroid point
 */
public Point getCentroid() {
    return GeometryUtils.getCentroid(geometry);
}
 
Example #24
Source File: ObservationLocation.java    From mage-android with Apache License 2.0 2 votes vote down vote up
/**
 * Get the geometry centroid as a LatLng
 *
 * @return centroid point lat lng
 */
public LatLng getCentroidLatLng() {
    Point point = GeometryUtils.getCentroid(geometry);
    return new LatLng(point.getY(), point.getX());
}