mil.nga.sf.Geometry Java Examples

The following examples show how to use mil.nga.sf.Geometry. 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: FeatureCoreGenerator.java    From geopackage-core-java with MIT License 6 votes vote down vote up
/**
 * Create the feature
 *
 * @param geometry
 *            geometry
 * @param properties
 *            properties
 * @throws SQLException
 *             upon error
 */
protected void createFeature(Geometry geometry,
		Map<String, Object> properties) throws SQLException {

	if (srs == null) {
		createSrs();
	}

	if (geometryColumns == null) {
		createTable(properties);
	}

	Map<String, Object> values = new HashMap<>();

	for (Entry<String, Object> property : properties.entrySet()) {
		String column = property.getKey();
		Object value = getValue(column, property.getValue());
		values.put(column, value);
	}

	saveFeature(geometry, values);

}
 
Example #2
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 #3
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 #4
Source File: ObservationFeedFragment.java    From mage-android with Apache License 2.0 6 votes vote down vote up
private ObservationLocation getLocation() {
	ObservationLocation location = null;

	// if there is not a location from the location service, then try to pull one from the database.
	if (locationProvider.getValue() == null) {
		List<mil.nga.giat.mage.sdk.datastore.location.Location> locations = LocationHelper.getInstance(context).getCurrentUserLocations(1, true);
		if (!locations.isEmpty()) {
			mil.nga.giat.mage.sdk.datastore.location.Location tLocation = locations.get(0);
			Geometry geo = tLocation.getGeometry();
			Map<String, LocationProperty> propertiesMap = tLocation.getPropertiesMap();
			String provider = ObservationLocation.MANUAL_PROVIDER;
			if (propertiesMap.get("provider").getValue() != null) {
				provider = propertiesMap.get("provider").getValue().toString();
			}
			location = new ObservationLocation(provider, geo);
			location.setTime(tLocation.getTimestamp().getTime());
			if (propertiesMap.get("accuracy").getValue() != null) {
				location.setAccuracy(Float.valueOf(propertiesMap.get("accuracy").getValue().toString()));
			}
		}
	} else {
		location = new ObservationLocation(locationProvider.getValue());
	}

	return location;
}
 
Example #5
Source File: FeatureUtils.java    From geopackage-java with MIT License 6 votes vote down vote up
/**
 * Validate Point
 * 
 * @param topGeometry
 * @param point
 */
private static void validatePoint(Geometry topGeometry, Point point) {

	TestCase.assertEquals(GeometryType.POINT, point.getGeometryType());

	validateZAndM(topGeometry, point);

	if (topGeometry.hasZ()) {
		TestCase.assertNotNull(point.getZ());
	} else {
		TestCase.assertNull(point.getZ());
	}

	if (topGeometry.hasM()) {
		TestCase.assertNotNull(point.getM());
	} else {
		TestCase.assertNull(point.getM());
	}
}
 
Example #6
Source File: FeatureUtils.java    From geopackage-android with MIT License 6 votes vote down vote up
/**
 * Validate Point
 *
 * @param topGeometry
 * @param point
 */
private static void validatePoint(Geometry topGeometry, Point point) {

    TestCase.assertEquals(GeometryType.POINT, point.getGeometryType());

    validateZAndM(topGeometry, point);

    if (topGeometry.hasZ()) {
        TestCase.assertNotNull(point.getZ());
    } else {
        TestCase.assertNull(point.getZ());
    }

    if (topGeometry.hasM()) {
        TestCase.assertNotNull(point.getM());
    } else {
        TestCase.assertNull(point.getM());
    }
}
 
Example #7
Source File: GeoPackagePerformance.java    From geopackage-java with MIT License 6 votes vote down vote up
private static Geometry createGeometry() {

		Polygon polygon = new Polygon();
		LineString ring = new LineString();
		ring.addPoint(new Point(-104.802246, 39.720343));
		ring.addPoint(new Point(-104.802246, 39.719753));
		ring.addPoint(new Point(-104.802183, 39.719754));
		ring.addPoint(new Point(-104.802184, 39.719719));
		ring.addPoint(new Point(-104.802138, 39.719694));
		ring.addPoint(new Point(-104.802097, 39.719691));
		ring.addPoint(new Point(-104.802096, 39.719648));
		ring.addPoint(new Point(-104.801646, 39.719648));
		ring.addPoint(new Point(-104.801644, 39.719722));
		ring.addPoint(new Point(-104.801550, 39.719723));
		ring.addPoint(new Point(-104.801549, 39.720207));
		ring.addPoint(new Point(-104.801648, 39.720207));
		ring.addPoint(new Point(-104.801648, 39.720341));
		ring.addPoint(new Point(-104.802246, 39.720343));
		polygon.addRing(ring);

		return polygon;
	}
 
Example #8
Source File: GeoPackagePerformance.java    From geopackage-android with MIT License 6 votes vote down vote up
private static Geometry createGeometry() {

        Polygon polygon = new Polygon();
        LineString ring = new LineString();
        ring.addPoint(new Point(-104.802246, 39.720343));
        ring.addPoint(new Point(-104.802246, 39.719753));
        ring.addPoint(new Point(-104.802183, 39.719754));
        ring.addPoint(new Point(-104.802184, 39.719719));
        ring.addPoint(new Point(-104.802138, 39.719694));
        ring.addPoint(new Point(-104.802097, 39.719691));
        ring.addPoint(new Point(-104.802096, 39.719648));
        ring.addPoint(new Point(-104.801646, 39.719648));
        ring.addPoint(new Point(-104.801644, 39.719722));
        ring.addPoint(new Point(-104.801550, 39.719723));
        ring.addPoint(new Point(-104.801549, 39.720207));
        ring.addPoint(new Point(-104.801648, 39.720207));
        ring.addPoint(new Point(-104.801648, 39.720341));
        ring.addPoint(new Point(-104.802246, 39.720343));
        polygon.addRing(ring);

        return polygon;
    }
 
Example #9
Source File: FeatureRow.java    From geopackage-java with MIT License 5 votes vote down vote up
/**
 * Get the simple features geometry type
 * 
 * @return geometry type
 * @since 3.2.0
 */
public GeometryType getGeometryType() {
	Geometry geometry = getGeometryValue();
	GeometryType geometryType = null;
	if (geometry != null) {
		geometryType = geometry.getGeometryType();
	}
	return geometryType;
}
 
Example #10
Source File: FeatureIndexer.java    From geopackage-android with MIT License 5 votes vote down vote up
/**
 * Index the feature row
 *
 * @param geoPackageId   GeoPackage id
 * @param row            feature row
 * @param possibleUpdate possible update flag
 * @return true if indexed
 */
private boolean index(long geoPackageId, FeatureRow row, boolean possibleUpdate) {

    boolean indexed = false;

    GeoPackageGeometryData geomData = row.getGeometry();
    if (geomData != null) {

        // Get the envelope
        GeometryEnvelope envelope = geomData.getEnvelope();

        // If no envelope, build one from the geometry
        if (envelope == null) {
            Geometry geometry = geomData.getGeometry();
            if (geometry != null) {
                envelope = GeometryEnvelopeBuilder.buildEnvelope(geometry);
            }
        }

        // Create the new index row
        if (envelope != null) {
            GeometryMetadata metadata = geometryMetadataDataSource.populate(geoPackageId, featureDao.getTableName(), row.getId(), envelope);
            if (possibleUpdate) {
                geometryMetadataDataSource.createOrUpdate(metadata);
            } else {
                geometryMetadataDataSource.create(metadata);
            }
            indexed = true;
        }
    }

    return indexed;
}
 
Example #11
Source File: OAPIFeatureGenerator.java    From geopackage-java with MIT License 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
protected void saveFeature(Geometry geometry, Map<String, Object> values) {

	FeatureRow featureRow = featureDao.newRow();

	featureRow.setGeometry(createGeometryData(geometry));
	for (Entry<String, Object> value : values.entrySet()) {
		featureRow.setValue(value.getKey(), value.getValue());
	}

	saveFeature(featureRow);
}
 
Example #12
Source File: GeoPackageGeometryDataUtils.java    From geopackage-android with MIT License 5 votes vote down vote up
/**
 * Compare to the base attribiutes of two geometries
 *
 * @param expected
 * @param actual
 */
private static void compareBaseGeometryAttributes(Geometry expected,
                                                  Geometry actual) {
    TestCase.assertEquals(expected.getGeometryType(),
            actual.getGeometryType());
    TestCase.assertEquals(expected.hasZ(), actual.hasZ());
    TestCase.assertEquals(expected.hasM(), actual.hasM());
    TestCase.assertEquals(GeometryCodes.getCode(expected), GeometryCodes.getCode(actual));
}
 
Example #13
Source File: GoogleMapShapeConverter.java    From geopackage-android-map with MIT License 5 votes vote down vote up
/**
 * Convert a {@link GeometryCollection} to a list of Map shapes and add to
 * the map
 *
 * @param map                google map
 * @param geometryCollection geometry collection
 * @return google map shapes
 */
public List<GoogleMapShape> addToMap(GoogleMap map,
                                     GeometryCollection<Geometry> geometryCollection) {

    List<GoogleMapShape> shapes = new ArrayList<GoogleMapShape>();

    for (Geometry geometry : geometryCollection.getGeometries()) {
        GoogleMapShape shape = addToMap(map, geometry);
        shapes.add(shape);
    }

    return shapes;
}
 
Example #14
Source File: FeatureRow.java    From geopackage-android with MIT License 5 votes vote down vote up
/**
 * Get the simple features geometry type
 *
 * @return geometry type
 * @since 3.2.0
 */
public GeometryType getGeometryType() {
    Geometry geometry = getGeometryValue();
    GeometryType geometryType = null;
    if (geometry != null) {
        geometryType = geometry.getGeometryType();
    }
    return geometryType;
}
 
Example #15
Source File: FeatureUtils.java    From geopackage-java with MIT License 5 votes vote down vote up
/**
 * Validate Multi Point
 * 
 * @param topGeometry
 * @param multiPoint
 */
private static void validateMultiPoint(Geometry topGeometry,
		MultiPoint multiPoint) {

	TestCase.assertEquals(GeometryType.MULTIPOINT,
			multiPoint.getGeometryType());

	validateZAndM(topGeometry, multiPoint);

	for (Point point : multiPoint.getPoints()) {
		validatePoint(topGeometry, point);
	}

}
 
Example #16
Source File: FeatureRow.java    From geopackage-android with MIT License 5 votes vote down vote up
/**
 * Get the simple features geometry value
 *
 * @return geometry
 * @since 3.1.0
 */
public Geometry getGeometryValue() {
    GeoPackageGeometryData data = getGeometry();
    Geometry geometry = null;
    if (data != null) {
        geometry = data.getGeometry();
    }
    return geometry;
}
 
Example #17
Source File: GeoPackageExample.java    From geopackage-android with MIT License 5 votes vote down vote up
private static void createFeatures(GeoPackage geoPackage,
                                   SpatialReferenceSystem srs, String tableName, GeometryType type,
                                   Geometry geometry, String name) throws SQLException {

    List<Geometry> geometries = new ArrayList<>();
    geometries.add(geometry);
    List<String> names = new ArrayList<>();
    names.add(name);

    createFeatures(geoPackage, srs, tableName, type, geometries, names);
}
 
Example #18
Source File: FeatureUtils.java    From geopackage-android with MIT License 5 votes vote down vote up
/**
 * Validate Line String
 *
 * @param topGeometry
 * @param lineString
 */
private static void validateLineString(Geometry topGeometry,
                                       LineString lineString) {

    TestCase.assertEquals(GeometryType.LINESTRING,
            lineString.getGeometryType());

    validateZAndM(topGeometry, lineString);

    for (Point point : lineString.getPoints()) {
        validatePoint(topGeometry, point);
    }

}
 
Example #19
Source File: FeatureUtils.java    From geopackage-java with MIT License 5 votes vote down vote up
/**
 * Validate Geometry Collection
 * 
 * @param topGeometry
 * @param geometryCollection
 */
private static void validateGeometryCollection(Geometry topGeometry,
		GeometryCollection<?> geometryCollection) {

	validateZAndM(topGeometry, geometryCollection);

	for (Geometry geometry : geometryCollection.getGeometries()) {
		validateGeometry(geometry.getGeometryType(), geometry);
	}

}
 
Example #20
Source File: GoogleMapShapeConverter.java    From geopackage-android-map with MIT License 5 votes vote down vote up
/**
 * Convert a {@link GeometryCollection} to a list of Map shapes
 *
 * @param geometryCollection geometry collection
 * @return google map shapes
 */
public List<GoogleMapShape> toShapes(
        GeometryCollection<Geometry> geometryCollection) {

    List<GoogleMapShape> shapes = new ArrayList<GoogleMapShape>();

    for (Geometry geometry : geometryCollection.getGeometries()) {
        GoogleMapShape shape = toShape(geometry);
        shapes.add(shape);
    }

    return shapes;
}
 
Example #21
Source File: LocationMarkerCollection.java    From mage-android with Apache License 2.0 5 votes vote down vote up
@Override
public void add(MarkerOptions options, Pair<Location, User> pair) {
	Location location = pair.first;
	User user = pair.second;

	final Geometry g = location.getGeometry();
	if (g != null) {

		// one user has one location
		Marker marker = userIdToMarker.get(user.getId());
		if (marker != null) {
			markerIdToPair.remove(marker.getId());
			marker.remove();

			if (clickedAccuracyCircleUserId != null && clickedAccuracyCircleUserId.equals(user.getId())) {
				if (clickedAccuracyCircle != null) {
					clickedAccuracyCircle.remove();
					clickedAccuracyCircle = null;
				}
			}
		}

		options.visible(visible);

		marker = map.addMarker(options);
		userIdToMarker.put(user.getId(), marker);
		markerIdToPair.put(marker.getId(), pair);

		if (location.getTimestamp().after(latestLocationDate)) {
			latestLocationDate = location.getTimestamp();
		}
	}
}
 
Example #22
Source File: FeatureInfoBuilder.java    From geopackage-android-map with MIT License 5 votes vote down vote up
/**
 * Project the geometry into the provided projection
 *
 * @param geometryData geometry data
 * @param projection   projection
 */
public void projectGeometry(GeoPackageGeometryData geometryData, Projection projection) {

    if (geometryData.getGeometry() != null) {

        try {
            SpatialReferenceSystemDao srsDao = DaoManager.createDao(featureDao.getDb().getConnectionSource(), SpatialReferenceSystem.class);
            int srsId = geometryData.getSrsId();
            SpatialReferenceSystem srs = srsDao.queryForId((long) srsId);

            if (!projection.equals(srs.getOrganization(), srs.getOrganizationCoordsysId())) {

                Projection geomProjection = srs.getProjection();
                ProjectionTransform transform = geomProjection.getTransformation(projection);

                Geometry projectedGeometry = transform.transform(geometryData.getGeometry());
                geometryData.setGeometry(projectedGeometry);
                SpatialReferenceSystem projectionSrs = srsDao.getOrCreateCode(projection.getAuthority(), Long.parseLong(projection.getCode()));
                geometryData.setSrsId((int) projectionSrs.getSrsId());
            }
        } catch (SQLException e) {
            throw new GeoPackageException("Failed to project geometry to projection with Authority: "
                    + projection.getAuthority() + ", Code: " + projection.getCode(), e);
        }
    }

}
 
Example #23
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 #24
Source File: MyHistoricalLocationMarkerCollection.java    From mage-android with Apache License 2.0 5 votes vote down vote up
@Override
public void add(MarkerOptions options, Pair<Location, User> pair) {
	Location location = pair.first;
	final Geometry gometry = location.getGeometry();

	if (gometry != null) {
		options.visible(visible);
		Marker marker = map.addMarker(options);
		markerIdToLocation.put(marker.getId(), pair);
		Marker oldMarker = locationIdToMarker.put(location.getId(), marker);
		if (oldMarker != null) {
			oldMarker.remove();
		}

		locationQueue.add(location);

		while (locationQueue.size() > LocationPushTask.Companion.getMinNumberOfLocationsToKeep()) {
			Location locationToRemove = locationQueue.poll();

			Marker markerToRemove = locationIdToMarker.remove(locationToRemove.getId());
			if (markerToRemove != null) {
				markerToRemove.remove();
				markerIdToLocation.remove(markerToRemove.getId());
			}
		}
	}
}
 
Example #25
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 #26
Source File: FeatureRow.java    From geopackage-java with MIT License 5 votes vote down vote up
/**
 * Get the simple features geometry value
 * 
 * @return geometry
 * @since 3.1.0
 */
public Geometry getGeometryValue() {
	GeoPackageGeometryData data = getGeometry();
	Geometry geometry = null;
	if (data != null) {
		geometry = data.getGeometry();
	}
	return geometry;
}
 
Example #27
Source File: GeoPackageGeometryData.java    From geopackage-core-java with MIT License 5 votes vote down vote up
/**
 * Get the envelope if it exists or build it from the geometry if not null
 * 
 * @return geometry envelope
 * @since 3.1.0
 */
public GeometryEnvelope getOrBuildEnvelope() {
	GeometryEnvelope envelope = getEnvelope();
	if (envelope == null) {
		Geometry geometry = getGeometry();
		if (geometry != null) {
			envelope = GeometryEnvelopeBuilder.buildEnvelope(geometry);
		}
	}
	return envelope;
}
 
Example #28
Source File: GeoPackageGeometryData.java    From geopackage-core-java with MIT License 5 votes vote down vote up
/**
 * Set the geometry. Updates the empty flag and if the geometry is not null,
 * the extended flag
 * 
 * @param geometry
 *            geometry
 */
public void setGeometry(Geometry geometry) {
	this.geometry = geometry;
	empty = geometry == null;
	if (geometry != null) {
		extended = GeometryExtensions.isNonStandard(geometry
				.getGeometryType());
	}
}
 
Example #29
Source File: GeoPackageGeometryDataUtils.java    From geopackage-java with MIT License 5 votes vote down vote up
/**
 * Compare to the base attributes of two geometries
 * 
 * @param expected
 * @param actual
 */
private static void compareBaseGeometryAttributes(Geometry expected,
		Geometry actual) {
	TestCase.assertEquals(expected.getGeometryType(),
			actual.getGeometryType());
	TestCase.assertEquals(expected.hasZ(), actual.hasZ());
	TestCase.assertEquals(expected.hasM(), actual.hasM());
	TestCase.assertEquals(GeometryCodes.getCode(expected),
			GeometryCodes.getCode(actual));
}
 
Example #30
Source File: FeatureUtils.java    From geopackage-java with MIT License 5 votes vote down vote up
/**
 * Validate Line String
 * 
 * @param topGeometry
 * @param lineString
 */
private static void validateLineString(Geometry topGeometry,
		LineString lineString) {

	TestCase.assertEquals(GeometryType.LINESTRING,
			lineString.getGeometryType());

	validateZAndM(topGeometry, lineString);

	for (Point point : lineString.getPoints()) {
		validatePoint(topGeometry, point);
	}

}