mil.nga.geopackage.features.user.FeatureRow Java Examples

The following examples show how to use mil.nga.geopackage.features.user.FeatureRow. 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: DefaultFeatureTiles.java    From geopackage-android with MIT License 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public Bitmap drawTile(int zoom, BoundingBox boundingBox, List<FeatureRow> featureRow) {

    FeatureTileCanvas canvas = new FeatureTileCanvas(tileWidth, tileHeight);

    ProjectionTransform transform = getProjectionToWebMercatorTransform(featureDao.getProjection());
    BoundingBox expandedBoundingBox = expandBoundingBox(boundingBox);

    boolean drawn = false;
    for (FeatureRow row : featureRow) {
        if (drawFeature(zoom, boundingBox, expandedBoundingBox, transform, canvas, row)) {
            drawn = true;
        }
    }

    Bitmap bitmap = null;
    if (drawn) {
        bitmap = canvas.createBitmap();
        bitmap = checkIfDrawn(bitmap);
    } else {
        canvas.recycle();
    }

    return bitmap;
}
 
Example #2
Source File: FeatureTableIndex.java    From geopackage-java with MIT License 6 votes vote down vote up
/**
 * Index the feature row. This method assumes that indexing has been
 * completed and maintained as the last indexed time is updated.
 *
 * @param row
 *            feature row
 * @return true if indexed
 */
public boolean index(FeatureRow row) {
	TableIndex tableIndex = getTableIndex();
	if (tableIndex == null) {
		throw new GeoPackageException(
				"GeoPackage table is not indexed. GeoPackage: "
						+ getGeoPackage().getName() + ", Table: "
						+ getTableName());
	}
	boolean indexed = index(tableIndex, row.getId(), row.getGeometry());

	// Update the last indexed time
	updateLastIndexed();

	return indexed;
}
 
Example #3
Source File: FeatureIndexRTreeResults.java    From geopackage-java with MIT License 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public Iterator<FeatureRow> iterator() {
	return new Iterator<FeatureRow>() {

		/**
		 * {@inheritDoc}
		 */
		@Override
		public boolean hasNext() {
			return resultSet.moveToNext();
		}

		/**
		 * {@inheritDoc}
		 */
		@Override
		public FeatureRow next() {
			return dao.getFeatureRow(resultSet);
		}
	};
}
 
Example #4
Source File: FeatureIndexManager.java    From geopackage-android with MIT License 6 votes vote down vote up
/**
 * Index the feature row. This method assumes that indexing has been completed and
 * maintained as the last indexed time is updated.
 *
 * @param type index location type
 * @param row  feature row to index
 * @return true if indexed
 */
public boolean index(FeatureIndexType type, FeatureRow row) {
    boolean indexed = false;
    if (type == null) {
        throw new GeoPackageException("FeatureIndexType is required to index");
    }
    switch (type) {
        case GEOPACKAGE:
            indexed = featureTableIndex.index(row);
            break;
        case METADATA:
            indexed = featureIndexer.index(row);
            break;
        case RTREE:
            // Updated by triggers, ignore for RTree
            indexed = true;
            break;
        default:
            throw new GeoPackageException("Unsupported FeatureIndexType: " + type);
    }
    return indexed;
}
 
Example #5
Source File: FeatureIndexMetadataResults.java    From geopackage-android with MIT License 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public Iterator<FeatureRow> iterator() {
    return new Iterator<FeatureRow>() {

        @Override
        public boolean hasNext() {
            return geometryMetadata.getCount() > 0 && !geometryMetadata.isLast();
        }

        @Override
        public FeatureRow next() {
            geometryMetadata.moveToNext();
            FeatureRow featureRow = featureIndexer.getFeatureRow(geometryMetadata);
            return featureRow;
        }
    };
}
 
Example #6
Source File: FeatureIndexManagerUtils.java    From geopackage-android with MIT License 5 votes vote down vote up
private static void iterateResults(TestTimer timerIteration, String message,
                                   FeatureIndexResults results) {
    timerIteration.start();
    for (@SuppressWarnings("unused")
            FeatureRow featureRow : results) {
    }
    timerIteration.end(message);
}
 
Example #7
Source File: FeatureIndexManagerUtils.java    From geopackage-android with MIT License 5 votes vote down vote up
/**
 * Validate a Feature Row result
 *
 * @param featureIndexManager
 * @param featureRow
 * @param queryEnvelope
 */
private static void validateFeatureRow(
        FeatureIndexManager featureIndexManager, FeatureRow featureRow,
        GeometryEnvelope queryEnvelope, boolean includeEmpty) {
    TestCase.assertNotNull(featureRow);
    GeometryEnvelope envelope = featureRow.getGeometryEnvelope();

    if (!includeEmpty) {
        TestCase.assertNotNull(envelope);

        if (queryEnvelope != null) {
            TestCase.assertTrue(envelope.getMinX() <= queryEnvelope
                    .getMaxX());
            TestCase.assertTrue(envelope.getMaxX() >= queryEnvelope
                    .getMinX());
            TestCase.assertTrue(envelope.getMinY() <= queryEnvelope
                    .getMaxY());
            TestCase.assertTrue(envelope.getMaxY() >= queryEnvelope
                    .getMinY());
            if (envelope.isHasZ()) {
                if (queryEnvelope.hasZ()) {
                    TestCase.assertTrue(envelope.getMinZ() <= queryEnvelope
                            .getMaxZ());
                    TestCase.assertTrue(envelope.getMaxZ() >= queryEnvelope
                            .getMinZ());
                }
            }
            if (envelope.isHasM()) {
                if (queryEnvelope.hasM()) {
                    TestCase.assertTrue(envelope.getMinM() <= queryEnvelope
                            .getMaxM());
                    TestCase.assertTrue(envelope.getMaxM() >= queryEnvelope
                            .getMinM());
                }
            }
        }
    }
}
 
Example #8
Source File: FeatureStylesUtils.java    From geopackage-android with MIT License 5 votes vote down vote up
private static void validateRowStyles(
        FeatureTableStyles featureTableStyles, FeatureRow featureRow,
        GeometryType geometryType, StyleRow tableStyleDefault,
        Map<GeometryType, StyleRow> geometryTypeTableStyles,
        Map<Long, Map<GeometryType, StyleRow>> featureResultsStyles) {

    StyleRow styleRow = null;
    if (geometryType == null) {
        styleRow = featureTableStyles.getStyle(featureRow);
        geometryType = featureRow.getGeometryType();
    } else {
        styleRow = featureTableStyles.getStyle(featureRow, geometryType);
    }

    StyleRow expectedStyleRow = getExpectedRowStyle(featureRow,
            geometryType, tableStyleDefault, geometryTypeTableStyles,
            featureResultsStyles);

    if (expectedStyleRow != null) {
        TestCase.assertEquals(expectedStyleRow.getId(), styleRow.getId());
        TestCase.assertNotNull(styleRow.getTable());
        TestCase.assertTrue(styleRow.getId() >= 0);
        styleRow.getName();
        styleRow.getDescription();
        styleRow.getColor();
        styleRow.getHexColor();
        styleRow.getOpacity();
        styleRow.getWidth();
        styleRow.getFillColor();
        styleRow.getFillHexColor();
        styleRow.getFillOpacity();
    } else {
        TestCase.assertNull(styleRow);
    }

}
 
Example #9
Source File: FeatureTableIndexUtils.java    From geopackage-java with MIT License 5 votes vote down vote up
/**
 * Validate a Geometry Index result
 * 
 * @param featureTableIndex
 * @param geometryIndex
 */
private static void validateGeometryIndex(
		FeatureTableIndex featureTableIndex, GeometryIndex geometryIndex) {
	FeatureRow featureRow = featureTableIndex.getFeatureRow(geometryIndex);
	TestCase.assertNotNull(featureRow);
	TestCase.assertEquals(featureTableIndex.getTableName(),
			geometryIndex.getTableName());
	TestCase.assertEquals(geometryIndex.getGeomId(), featureRow.getId());
	GeometryEnvelope envelope = featureRow.getGeometryEnvelope();

	TestCase.assertNotNull(envelope);

	TestCase.assertEquals(envelope.getMinX(), geometryIndex.getMinX());
	TestCase.assertEquals(envelope.getMaxX(), geometryIndex.getMaxX());
	TestCase.assertEquals(envelope.getMinY(), geometryIndex.getMinY());
	TestCase.assertEquals(envelope.getMaxY(), geometryIndex.getMaxY());
	if (envelope.isHasZ()) {
		TestCase.assertEquals(envelope.getMinZ(), geometryIndex.getMinZ());
		TestCase.assertEquals(envelope.getMaxZ(), geometryIndex.getMaxZ());
	} else {
		TestCase.assertNull(geometryIndex.getMinZ());
		TestCase.assertNull(geometryIndex.getMaxZ());
	}
	if (envelope.isHasM()) {
		TestCase.assertEquals(envelope.getMinM(), geometryIndex.getMinM());
		TestCase.assertEquals(envelope.getMaxM(), geometryIndex.getMaxM());
	} else {
		TestCase.assertNull(geometryIndex.getMinM());
		TestCase.assertNull(geometryIndex.getMaxM());
	}
}
 
Example #10
Source File: FeatureTiles.java    From geopackage-java with MIT License 5 votes vote down vote up
/**
 * Get the feature style for the feature row and geometry type
 *
 * @param featureRow
 *            feature row
 * @return feature style
 */
protected FeatureStyle getFeatureStyle(FeatureRow featureRow) {
	FeatureStyle featureStyle = null;
	if (featureTableStyles != null) {
		featureStyle = featureTableStyles.getFeatureStyle(featureRow);
	}
	return featureStyle;
}
 
Example #11
Source File: TransactionTest.java    From geopackage-java with MIT License 5 votes vote down vote up
/**
 * Insert a row into the feature table
 *
 * @param featureDao
 *            feature dao
 */
private void insertRow(FeatureDao featureDao) {

	FeatureRow row = featureDao.newRow();
	GeoPackageGeometryData geometry = new GeoPackageGeometryData(featureDao
			.getGeometryColumns().getSrsId());
	geometry.setGeometry(new Point(0, 0));
	row.setGeometry(geometry);
	featureDao.insert(row);

}
 
Example #12
Source File: FeatureIndexer.java    From geopackage-android with MIT License 5 votes vote down vote up
/**
 * Index the feature rows in the cursor
 *
 * @param geoPackageId GeoPackage id
 * @param cursor       feature cursor
 * @return count, -1 if no results or canceled
 */
private int indexRows(long geoPackageId, FeatureCursor cursor) {

    int count = -1;

    try {
        while ((progress == null || progress.isActive())
                && cursor.moveToNext()) {
            if (count < 0) {
                count++;
            }
            try {
                FeatureRow row = cursor.getRow();
                if (row.isValid()) {
                    boolean indexed = index(geoPackageId, row, false);
                    if (indexed) {
                        count++;
                    }
                    if (progress != null) {
                        progress.addProgress(1);
                    }
                }
            } catch (Exception e) {
                Log.e(FeatureIndexer.class.getSimpleName(), "Failed to index feature. Table: "
                        + featureDao.getTableName() + ", Position: " + cursor.getPosition(), e);
            }
        }
    } finally {
        cursor.close();
    }

    return count;
}
 
Example #13
Source File: FeatureTiles.java    From geopackage-android with MIT License 5 votes vote down vote up
/**
 * Get the feature style for the feature row and geometry type
 *
 * @param featureRow feature row
 * @return feature style
 */
protected FeatureStyle getFeatureStyle(FeatureRow featureRow) {
    FeatureStyle featureStyle = null;
    if (featureTableStyles != null) {
        featureStyle = featureTableStyles.getFeatureStyle(featureRow);
    }
    return featureStyle;
}
 
Example #14
Source File: FeatureTableIndexUtils.java    From geopackage-android with MIT License 5 votes vote down vote up
/**
 * Validate a Geometry Index result
 *
 * @param featureTableIndex
 * @param geometryIndex
 */
private static void validateGeometryIndex(
        FeatureTableIndex featureTableIndex, GeometryIndex geometryIndex) {
    FeatureRow featureRow = featureTableIndex.getFeatureRow(geometryIndex);
    TestCase.assertNotNull(featureRow);
    TestCase.assertEquals(featureTableIndex.getTableName(),
            geometryIndex.getTableName());
    TestCase.assertEquals(geometryIndex.getGeomId(), featureRow.getId());
    GeometryEnvelope envelope = featureRow.getGeometryEnvelope();

    TestCase.assertNotNull(envelope);

    TestCase.assertEquals(envelope.getMinX(), geometryIndex.getMinX());
    TestCase.assertEquals(envelope.getMaxX(), geometryIndex.getMaxX());
    TestCase.assertEquals(envelope.getMinY(), geometryIndex.getMinY());
    TestCase.assertEquals(envelope.getMaxY(), geometryIndex.getMaxY());
    if (envelope.isHasZ()) {
        TestCase.assertEquals(envelope.getMinZ(), geometryIndex.getMinZ());
        TestCase.assertEquals(envelope.getMaxZ(), geometryIndex.getMaxZ());
    } else {
        TestCase.assertNull(geometryIndex.getMinZ());
        TestCase.assertNull(geometryIndex.getMaxZ());
    }
    if (envelope.isHasM()) {
        TestCase.assertEquals(envelope.getMinM(), geometryIndex.getMinM());
        TestCase.assertEquals(envelope.getMaxM(), geometryIndex.getMaxM());
    } else {
        TestCase.assertNull(geometryIndex.getMinM());
        TestCase.assertNull(geometryIndex.getMaxM());
    }
}
 
Example #15
Source File: DefaultFeatureTiles.java    From geopackage-java with MIT License 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public BufferedImage drawTile(int zoom, BoundingBox boundingBox,
		CloseableIterator<GeometryIndex> results) {

	FeatureTileGraphics graphics = new FeatureTileGraphics(tileWidth,
			tileHeight);

	// Feature projection to web mercator projection
	ProjectionTransform webMercatorTransform = getWebMercatorTransform();
	BoundingBox expandedBoundingBox = expandBoundingBox(boundingBox);

	boolean drawn = false;
	while (results.hasNext()) {
		GeometryIndex geometryIndex = results.next();
		FeatureRow featureRow = getFeatureIndex()
				.getFeatureRow(geometryIndex);
		if (drawFeature(zoom, boundingBox, expandedBoundingBox,
				webMercatorTransform, graphics, featureRow)) {
			drawn = true;
		}
	}
	try {
		results.close();
	} catch (IOException e) {
		log.log(Level.WARNING, "Failed to close geometry index results", e);
	}

	BufferedImage image = null;
	if (drawn) {
		image = graphics.createImage();
		image = checkIfDrawn(image);
	} else {
		graphics.dispose();
	}

	return image;
}
 
Example #16
Source File: FeatureTableIndex.java    From geopackage-java with MIT License 5 votes vote down vote up
/**
 * Index the feature rows in the cursor
 * 
 * @param tableIndex
 *            table index
 * @param resultSet
 *            feature result
 * @return count, -1 if no results or canceled
 */
private int indexRows(TableIndex tableIndex, FeatureResultSet resultSet) {

	int count = -1;

	try {
		while ((progress == null || progress.isActive())
				&& resultSet.moveToNext()) {
			if (count < 0) {
				count++;
			}
			try {
				FeatureRow row = resultSet.getRow();
				boolean indexed = index(tableIndex, row.getId(),
						row.getGeometry());
				if (indexed) {
					count++;
				}
				if (progress != null) {
					progress.addProgress(1);
				}
			} catch (Exception e) {
				log.log(Level.SEVERE,
						"Failed to index feature. Table: "
								+ tableIndex.getTableName() + ", Position: "
								+ resultSet.getPosition(),
						e);
			}
		}
	} finally {
		resultSet.close();
	}

	return count;
}
 
Example #17
Source File: FeatureTableIndex.java    From geopackage-android with MIT License 5 votes vote down vote up
/**
 * Index the feature rows in the cursor
 *
 * @param tableIndex table index
 * @param cursor     feature cursor
 * @return count, -1 if no results or canceled
 */
private int indexRows(TableIndex tableIndex, FeatureCursor cursor) {

    int count = -1;

    try {
        while ((progress == null || progress.isActive())
                && cursor.moveToNext()) {
            if (count < 0) {
                count++;
            }
            try {
                FeatureRow row = cursor.getRow();
                if (row.isValid()) {
                    boolean indexed = index(tableIndex,
                            row.getId(), row.getGeometry());
                    if (indexed) {
                        count++;
                    }
                    if (progress != null) {
                        progress.addProgress(1);
                    }
                }
            } catch (Exception e) {
                Log.e(FeatureTableIndex.class.getSimpleName(), "Failed to index feature. Table: "
                        + tableIndex.getTableName() + ", Position: " + cursor.getPosition(), e);
            }
        }
    } finally {
        cursor.close();
    }

    return count;
}
 
Example #18
Source File: DefaultFeatureTiles.java    From geopackage-java with MIT License 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public BufferedImage drawTile(int zoom, BoundingBox boundingBox,
		List<FeatureRow> featureRow) {

	FeatureTileGraphics graphics = new FeatureTileGraphics(tileWidth,
			tileHeight);

	ProjectionTransform webMercatorTransform = getWebMercatorTransform();
	BoundingBox expandedBoundingBox = expandBoundingBox(boundingBox);

	boolean drawn = false;
	for (FeatureRow row : featureRow) {
		if (drawFeature(zoom, boundingBox, expandedBoundingBox,
				webMercatorTransform, graphics, row)) {
			drawn = true;
		}
	}

	BufferedImage image = null;
	if (drawn) {
		image = graphics.createImage();
		image = checkIfDrawn(image);
	} else {
		graphics.dispose();
	}

	return image;
}
 
Example #19
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 #20
Source File: GeoPackageExample.java    From geopackage-java with MIT License 4 votes vote down vote up
private static void createRelatedTablesTilesExtension(
		GeoPackage geoPackage) {

	String featureTable = "point2";
	String tileTable = "nga";

	RelatedTablesExtension relatedTables = new RelatedTablesExtension(
			geoPackage);

	List<UserCustomColumn> additionalMappingColumns = RelatedTablesUtils
			.createAdditionalUserColumns();

	UserMappingTable userMappingTable = UserMappingTable.create(
			featureTable + "_" + tileTable, additionalMappingColumns);
	ExtendedRelation relation = relatedTables.addTilesRelationship(
			featureTable, tileTable, userMappingTable);

	UserMappingDao userMappingDao = relatedTables.getMappingDao(relation);

	FeatureDao featureDao = geoPackage
			.getFeatureDao(relation.getBaseTableName());
	TileDao tileDao = geoPackage.getTileDao(relation.getRelatedTableName());

	FeatureResultSet featureResultSet = featureDao.queryForAll();
	while (featureResultSet.moveToNext()) {

		FeatureRow featureRow = featureResultSet.getRow();
		String featureName = featureRow.getValue(TEXT_COLUMN).toString();

		TileResultSet tileResultSet = tileDao
				.queryForTile(tileDao.getMinZoom());
		while (tileResultSet.moveToNext()) {

			TileRow tileRow = tileResultSet.getRow();

			UserMappingRow userMappingRow = userMappingDao.newRow();
			userMappingRow.setBaseId(featureRow.getId());
			userMappingRow.setRelatedId(tileRow.getId());
			RelatedTablesUtils.populateUserRow(userMappingDao.getTable(),
					userMappingRow, UserMappingTable.requiredColumns());
			DublinCoreMetadata.setValue(userMappingRow,
					DublinCoreType.TITLE, featureName);
			DublinCoreMetadata.setValue(userMappingRow,
					DublinCoreType.DESCRIPTION, featureName);
			DublinCoreMetadata.setValue(userMappingRow,
					DublinCoreType.SOURCE, featureName);
			userMappingDao.create(userMappingRow);
		}
		tileResultSet.close();

	}
	featureResultSet.close();

}
 
Example #21
Source File: GeoPackageTestUtils.java    From geopackage-android with MIT License 4 votes vote down vote up
/**
 * Validate feature table with metadata
 *
 * @param geoPackage
 * @throws SQLException
 */
private static void validateFeatureTableWithMetadata(GeoPackage geoPackage,
                                                     GeometryColumns geometryColumns, String idColumn,
                                                     List<FeatureColumn> additionalColumns) throws SQLException {

    GeometryColumnsDao dao = geoPackage.getGeometryColumnsDao();

    GeometryColumns queryGeometryColumns = dao.queryForId(geometryColumns
            .getId());
    TestCase.assertNotNull(queryGeometryColumns);

    TestCase.assertEquals(geometryColumns.getTableName(),
            queryGeometryColumns.getTableName());
    TestCase.assertEquals(geometryColumns.getColumnName(),
            queryGeometryColumns.getColumnName());
    TestCase.assertEquals(GeometryType.POINT,
            queryGeometryColumns.getGeometryType());
    TestCase.assertEquals(geometryColumns.getZ(),
            queryGeometryColumns.getZ());
    TestCase.assertEquals(geometryColumns.getM(),
            queryGeometryColumns.getM());

    FeatureDao featureDao = geoPackage.getFeatureDao(geometryColumns
            .getTableName());
    FeatureRow featureRow = featureDao.newRow();

    TestCase.assertEquals(
            2 + (additionalColumns != null ? additionalColumns.size() : 0),
            featureRow.columnCount());
    if (idColumn == null) {
        idColumn = "id";
    }
    TestCase.assertEquals(idColumn, featureRow.getColumnName(0));
    TestCase.assertEquals(geometryColumns.getColumnName(),
            featureRow.getColumnName(1));

    if (additionalColumns != null) {
        TestCase.assertEquals("test_text", featureRow.getColumnName(2));
        TestCase.assertEquals("test_real", featureRow.getColumnName(3));
        TestCase.assertEquals("test_boolean", featureRow.getColumnName(4));
        TestCase.assertEquals("test_blob", featureRow.getColumnName(5));
        TestCase.assertEquals("test_integer", featureRow.getColumnName(6));
        TestCase.assertEquals("test_text_limited",
                featureRow.getColumnName(7));
        TestCase.assertEquals("test_blob_limited",
                featureRow.getColumnName(8));
    }
}
 
Example #22
Source File: DefaultFeatureTiles.java    From geopackage-android with MIT License 4 votes vote down vote up
/**
 * Draw the geometry on the canvas
 *
 * @param simplifyTolerance simplify tolerance in meters
 * @param boundingBox       bounding box
 * @param transform         projection transform
 * @param canvas            feature tile canvas
 * @param featureRow        feature row
 * @param geometry          feature geometry
 * @return true if drawn
 */
private boolean drawShape(double simplifyTolerance, BoundingBox boundingBox, ProjectionTransform transform, FeatureTileCanvas canvas, FeatureRow featureRow, Geometry geometry) {

    boolean drawn = false;

    GeometryType geometryType = geometry.getGeometryType();
    FeatureStyle featureStyle = getFeatureStyle(featureRow, geometryType);

    switch (geometryType) {

        case POINT:
            Point point = (Point) geometry;
            drawn = drawPoint(boundingBox, transform, canvas, point, featureStyle);
            break;
        case LINESTRING:
        case CIRCULARSTRING:
            LineString lineString = (LineString) geometry;
            Path linePath = new Path();
            addLineString(simplifyTolerance, boundingBox, transform, linePath, lineString);
            drawn = drawLinePath(canvas, linePath, featureStyle);
            break;
        case POLYGON:
        case TRIANGLE:
            Polygon polygon = (Polygon) geometry;
            Path polygonPath = new Path();
            addPolygon(simplifyTolerance, boundingBox, transform, polygonPath, polygon);
            drawn = drawPolygonPath(canvas, polygonPath, featureStyle);
            break;
        case MULTIPOINT:
            MultiPoint multiPoint = (MultiPoint) geometry;
            for (Point pointFromMulti : multiPoint.getPoints()) {
                drawn = drawPoint(boundingBox, transform, canvas, pointFromMulti, featureStyle) || drawn;
            }
            break;
        case MULTILINESTRING:
            MultiLineString multiLineString = (MultiLineString) geometry;
            Path multiLinePath = new Path();
            for (LineString lineStringFromMulti : multiLineString.getLineStrings()) {
                addLineString(simplifyTolerance, boundingBox, transform, multiLinePath, lineStringFromMulti);
            }
            drawn = drawLinePath(canvas, multiLinePath, featureStyle);
            break;
        case MULTIPOLYGON:
            MultiPolygon multiPolygon = (MultiPolygon) geometry;
            Path multiPolygonPath = new Path();
            for (Polygon polygonFromMulti : multiPolygon.getPolygons()) {
                addPolygon(simplifyTolerance, boundingBox, transform, multiPolygonPath, polygonFromMulti);
            }
            drawn = drawPolygonPath(canvas, multiPolygonPath, featureStyle);
            break;
        case COMPOUNDCURVE:
            CompoundCurve compoundCurve = (CompoundCurve) geometry;
            Path compoundCurvePath = new Path();
            for (LineString lineStringFromCompoundCurve : compoundCurve.getLineStrings()) {
                addLineString(simplifyTolerance, boundingBox, transform, compoundCurvePath, lineStringFromCompoundCurve);
            }
            drawn = drawLinePath(canvas, compoundCurvePath, featureStyle);
            break;
        case POLYHEDRALSURFACE:
        case TIN:
            PolyhedralSurface polyhedralSurface = (PolyhedralSurface) geometry;
            Path polyhedralSurfacePath = new Path();
            for (Polygon polygonFromPolyhedralSurface : polyhedralSurface.getPolygons()) {
                addPolygon(simplifyTolerance, boundingBox, transform, polyhedralSurfacePath, polygonFromPolyhedralSurface);
            }
            drawn = drawPolygonPath(canvas, polyhedralSurfacePath, featureStyle);
            break;
        case GEOMETRYCOLLECTION:
            @SuppressWarnings("unchecked")
            GeometryCollection<Geometry> geometryCollection = (GeometryCollection) geometry;
            List<Geometry> geometries = geometryCollection.getGeometries();
            for (Geometry geometryFromCollection : geometries) {
                drawn = drawShape(simplifyTolerance, boundingBox, transform, canvas, featureRow, geometryFromCollection) || drawn;
            }
            break;
        default:
            throw new GeoPackageException("Unsupported Geometry Type: "
                    + geometry.getGeometryType().getName());
    }

    return drawn;
}
 
Example #23
Source File: FeatureTileUtils.java    From geopackage-android with MIT License 4 votes vote down vote up
public static long insertPoint(FeatureDao featureDao, double x, double y) {
    FeatureRow featureRow = featureDao.newRow();
    setPoint(featureRow, x, y);
    return featureDao.insert(featureRow);
}
 
Example #24
Source File: FeatureInfoBuilder.java    From geopackage-android-map with MIT License 4 votes vote down vote up
/**
 * Build a feature results information message
 *
 * @param results       feature index results
 * @param tolerance     distance tolerance
 * @param clickLocation map click location
 * @param projection    desired geometry projection
 * @return feature table data or null if not results
 */
public FeatureTableData buildTableDataAndClose(FeatureIndexResults results, double tolerance, LatLng clickLocation, Projection projection) {

    FeatureTableData tableData = null;

    // Fine filter results so that the click location is within the tolerance of each feature row result
    FeatureIndexResults filteredResults = fineFilterResults(results, tolerance, clickLocation);

    long featureCount = filteredResults.count();
    if (featureCount > 0) {

        int maxFeatureInfo = 0;
        if (geometryType == GeometryType.POINT) {
            maxFeatureInfo = maxPointDetailedInfo;
        } else {
            maxFeatureInfo = maxFeatureDetailedInfo;
        }

        if (featureCount <= maxFeatureInfo) {

            DataColumnsDao dataColumnsDao = getDataColumnsDao();

            List<FeatureRowData> rows = new ArrayList<>();

            for (FeatureRow featureRow : filteredResults) {

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

                int geometryColumn = featureRow.getGeometryColumnIndex();
                for (int i = 0; i < featureRow.columnCount(); i++) {

                    Object value = featureRow.getValue(i);

                    String columnName = featureRow.getColumnName(i);

                    columnName = getColumnName(dataColumnsDao, featureRow, columnName);

                    if (i == geometryColumn) {
                        geometryColumnName = columnName;
                        if (projection != null && value != null) {
                            GeoPackageGeometryData geomData = (GeoPackageGeometryData) value;
                            projectGeometry(geomData, projection);
                        }
                    }

                    if (value != null) {
                        values.put(columnName, value);
                    }
                }

                FeatureRowData featureRowData = new FeatureRowData(values, geometryColumnName);
                rows.add(featureRowData);
            }

            tableData = new FeatureTableData(featureDao.getTableName(), featureCount, rows);
        } else {
            tableData = new FeatureTableData(featureDao.getTableName(), featureCount);
        }
    }

    results.close();

    return tableData;
}
 
Example #25
Source File: GeoPackageTestUtils.java    From geopackage-java with MIT License 4 votes vote down vote up
/**
 * Validate feature table with metadata
 * 
 * @param geoPackage
 * @throws SQLException
 */
private static void validateFeatureTableWithMetadata(GeoPackage geoPackage,
		GeometryColumns geometryColumns, String idColumn,
		List<FeatureColumn> additionalColumns) throws SQLException {

	GeometryColumnsDao dao = geoPackage.getGeometryColumnsDao();

	GeometryColumns queryGeometryColumns = dao
			.queryForId(geometryColumns.getId());
	TestCase.assertNotNull(queryGeometryColumns);

	TestCase.assertEquals(geometryColumns.getTableName(),
			queryGeometryColumns.getTableName());
	TestCase.assertEquals(geometryColumns.getColumnName(),
			queryGeometryColumns.getColumnName());
	TestCase.assertEquals(GeometryType.POINT,
			queryGeometryColumns.getGeometryType());
	TestCase.assertEquals(geometryColumns.getZ(),
			queryGeometryColumns.getZ());
	TestCase.assertEquals(geometryColumns.getM(),
			queryGeometryColumns.getM());

	FeatureDao featureDao = geoPackage
			.getFeatureDao(geometryColumns.getTableName());
	FeatureRow featureRow = featureDao.newRow();

	TestCase.assertEquals(
			2 + (additionalColumns != null ? additionalColumns.size() : 0),
			featureRow.columnCount());
	if (idColumn == null) {
		idColumn = "id";
	}
	TestCase.assertEquals(idColumn, featureRow.getColumnName(0));
	TestCase.assertEquals(geometryColumns.getColumnName(),
			featureRow.getColumnName(1));

	if (additionalColumns != null) {
		TestCase.assertEquals("test_text", featureRow.getColumnName(2));
		TestCase.assertEquals("test_real", featureRow.getColumnName(3));
		TestCase.assertEquals("test_boolean", featureRow.getColumnName(4));
		TestCase.assertEquals("test_blob", featureRow.getColumnName(5));
		TestCase.assertEquals("test_integer", featureRow.getColumnName(6));
		TestCase.assertEquals("test_text_limited",
				featureRow.getColumnName(7));
		TestCase.assertEquals("test_blob_limited",
				featureRow.getColumnName(8));
	}
}
 
Example #26
Source File: GeoPackageExample.java    From geopackage-java with MIT License 4 votes vote down vote up
private static void insertRelatedTablesMediaExtensionRows(
		GeoPackage geoPackage, ExtendedRelation relation, String query,
		String name, String file, String contentType, String description,
		String source) {

	RelatedTablesExtension relatedTables = new RelatedTablesExtension(
			geoPackage);

	FeatureDao featureDao = geoPackage
			.getFeatureDao(relation.getBaseTableName());
	MediaDao mediaDao = relatedTables.getMediaDao(relation);
	UserMappingDao userMappingDao = relatedTables.getMappingDao(relation);

	MediaRow mediaRow = mediaDao.newRow();
	mediaRow.setData(TestUtils.getTestFileBytes(file));
	mediaRow.setContentType(contentType);
	RelatedTablesUtils.populateUserRow(mediaDao.getTable(), mediaRow,
			MediaTable.requiredColumns());
	DublinCoreMetadata.setValue(mediaRow, DublinCoreType.TITLE, name);
	DublinCoreMetadata.setValue(mediaRow, DublinCoreType.DESCRIPTION,
			description);
	DublinCoreMetadata.setValue(mediaRow, DublinCoreType.SOURCE, source);
	long mediaRowId = mediaDao.create(mediaRow);

	FeatureResultSet featureResultSet = featureDao.queryForLike(TEXT_COLUMN,
			query);
	while (featureResultSet.moveToNext()) {
		FeatureRow featureRow = featureResultSet.getRow();
		UserMappingRow userMappingRow = userMappingDao.newRow();
		userMappingRow.setBaseId(featureRow.getId());
		userMappingRow.setRelatedId(mediaRowId);
		RelatedTablesUtils.populateUserRow(userMappingDao.getTable(),
				userMappingRow, UserMappingTable.requiredColumns());
		String featureName = featureRow.getValue(TEXT_COLUMN).toString();
		DublinCoreMetadata.setValue(userMappingRow, DublinCoreType.TITLE,
				featureName + " - " + name);
		DublinCoreMetadata.setValue(userMappingRow,
				DublinCoreType.DESCRIPTION,
				featureName + " - " + description);
		DublinCoreMetadata.setValue(userMappingRow, DublinCoreType.SOURCE,
				source);
		userMappingDao.create(userMappingRow);
	}
	featureResultSet.close();
}
 
Example #27
Source File: FeatureUtils.java    From geopackage-java with MIT License 4 votes vote down vote up
/**
 * Validate a feature row
 * 
 * @param columns
 * @param featureRow
 */
private static void validateFeatureRow(String[] columns,
		FeatureRow featureRow) {
	TestCase.assertEquals(columns.length, featureRow.columnCount());

	for (int i = 0; i < featureRow.columnCount(); i++) {
		FeatureColumn column = featureRow.getTable().getColumns().get(i);
		GeoPackageDataType dataType = column.getDataType();
		TestCase.assertEquals(i, column.getIndex());
		TestCase.assertEquals(columns[i], featureRow.getColumnName(i));
		TestCase.assertEquals(i, featureRow.getColumnIndex(columns[i]));
		int rowType = featureRow.getRowColumnType(i);
		Object value = featureRow.getValue(i);

		switch (rowType) {

		case ResultUtils.FIELD_TYPE_INTEGER:
			TestUtils.validateIntegerValue(value, column.getDataType());
			break;

		case ResultUtils.FIELD_TYPE_FLOAT:
			TestUtils.validateFloatValue(value, column.getDataType());
			break;

		case ResultUtils.FIELD_TYPE_STRING:
			if (dataType == GeoPackageDataType.DATE
					|| dataType == GeoPackageDataType.DATETIME) {
				TestCase.assertTrue(value instanceof Date);
				Date date = (Date) value;
				DateConverter converter = DateConverter.converter(dataType);
				String dateString = converter.stringValue(date);
				TestCase.assertEquals(date.getTime(),
						converter.dateValue(dateString).getTime());
			} else {
				TestCase.assertTrue(value instanceof String);
			}
			break;

		case ResultUtils.FIELD_TYPE_BLOB:
			if (featureRow.getGeometryColumnIndex() == i) {
				TestCase.assertTrue(value instanceof GeoPackageGeometryData);
			} else {
				TestCase.assertTrue(value instanceof byte[]);
			}
			break;

		case ResultUtils.FIELD_TYPE_NULL:
			TestCase.assertNull(value);
			break;

		}
	}

	TestCase.assertTrue(featureRow.getId() >= 0);
}
 
Example #28
Source File: StyleUtils.java    From geopackage-android-map with MIT License 3 votes vote down vote up
/**
 * Create new polyline options populated with the feature row style
 *
 * @param geoPackage GeoPackage
 * @param featureRow feature row
 * @param density    display density: {@link android.util.DisplayMetrics#density}
 * @return polyline options populated with the feature style
 */
public static PolylineOptions createPolylineOptions(GeoPackage geoPackage, FeatureRow featureRow, float density) {

    PolylineOptions polylineOptions = new PolylineOptions();
    setFeatureStyle(polylineOptions, geoPackage, featureRow, density);

    return polylineOptions;
}
 
Example #29
Source File: StyleUtils.java    From geopackage-android-map with MIT License 3 votes vote down vote up
/**
 * Create new marker options populated with the feature row style (icon or style)
 *
 * @param geoPackage GeoPackage
 * @param featureRow feature row
 * @param density    display density: {@link android.util.DisplayMetrics#density}
 * @param iconCache  icon cache
 * @return marker options populated with the feature style
 */
public static MarkerOptions createMarkerOptions(GeoPackage geoPackage, FeatureRow featureRow, float density, IconCache iconCache) {

    MarkerOptions markerOptions = new MarkerOptions();
    setFeatureStyle(markerOptions, geoPackage, featureRow, density, iconCache);

    return markerOptions;
}
 
Example #30
Source File: StyleUtils.java    From geopackage-android-map with MIT License 3 votes vote down vote up
/**
 * Create new polygon options populated with the feature row style
 *
 * @param featureStyleExtension feature style extension
 * @param featureRow            feature row
 * @param density               display density: {@link android.util.DisplayMetrics#density}
 * @return polygon options populated with the feature style
 */
public static PolygonOptions createPolygonOptions(FeatureStyleExtension featureStyleExtension, FeatureRow featureRow, float density) {

    PolygonOptions polygonOptions = new PolygonOptions();
    setFeatureStyle(polygonOptions, featureStyleExtension, featureRow, density);

    return polygonOptions;
}