Java Code Examples for mil.nga.geopackage.features.user.FeatureDao#queryForAll()

The following examples show how to use mil.nga.geopackage.features.user.FeatureDao#queryForAll() . 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: GeoPackageExample.java    From geopackage-android with MIT License 5 votes vote down vote up
private static void createFeatureStylesGeometry2(GeoPackage geoPackage,
                                                 List<StyleRow> styles, List<IconRow> icons) throws IOException {

    FeatureDao featureDao = geoPackage.getFeatureDao("geometry2");
    FeatureTableStyles geometry2Styles = new FeatureTableStyles(geoPackage,
            featureDao.getTable());

    geometry2Styles.setTableStyle(GeometryType.POINT, styles.get(0));
    geometry2Styles.setTableStyle(GeometryType.LINESTRING, styles.get(1));
    geometry2Styles.setTableStyle(GeometryType.POLYGON, styles.get(0));
    geometry2Styles.setTableStyle(GeometryType.GEOMETRY, styles.get(2));

    geometry2Styles.createStyleRelationship();
    geometry2Styles.createIconRelationship();

    FeatureCursor features = featureDao.queryForAll();
    while (features.moveToNext()) {
        FeatureRow featureRow = features.getRow();
        switch (featureRow.getGeometryType()) {
            case POINT:
                geometry2Styles.setIcon(featureRow, icons.get(0));
                break;
            case LINESTRING:
                geometry2Styles.setStyle(featureRow, styles.get(0));
                break;
            case POLYGON:
                geometry2Styles.setStyle(featureRow, styles.get(1));
                break;
            default:
        }
    }
    features.close();

}
 
Example 2
Source File: FeatureUtils.java    From geopackage-java with MIT License 5 votes vote down vote up
/**
 * Test delete
 * 
 * @param geoPackage
 *            GeoPackage
 * @throws SQLException
 *             upon error
 */
public static void testDelete(GeoPackage geoPackage) throws SQLException {

	GeometryColumnsDao geometryColumnsDao = geoPackage
			.getGeometryColumnsDao();

	if (geometryColumnsDao.isTableExists()) {
		List<GeometryColumns> results = geometryColumnsDao.queryForAll();

		for (GeometryColumns geometryColumns : results) {

			FeatureDao dao = geoPackage.getFeatureDao(geometryColumns);
			TestCase.assertNotNull(dao);

			FeatureResultSet cursor = dao.queryForAll();
			int count = cursor.getCount();
			if (count > 0) {

				// Choose random feature
				int random = (int) (Math.random() * count);
				cursor.moveToPosition(random);

				FeatureRow featureRow = cursor.getRow();
				cursor.close();

				// Delete row
				TestCase.assertEquals(1, dao.delete(featureRow));

				// Verify deleted
				FeatureRow queryFeatureRow = dao.queryForIdRow(featureRow
						.getId());
				TestCase.assertNull(queryFeatureRow);
				cursor = dao.queryForAll();
				TestCase.assertEquals(count - 1, cursor.getCount());
				cursor.close();
			}
			cursor.close();
		}
	}
}
 
Example 3
Source File: GeoPackageExample.java    From geopackage-java with MIT License 5 votes vote down vote up
private static void createFeatureStylesGeometry2(GeoPackage geoPackage,
		List<StyleRow> styles, List<IconRow> icons) throws IOException {

	FeatureDao featureDao = geoPackage.getFeatureDao("geometry2");
	FeatureTableStyles geometry2Styles = new FeatureTableStyles(geoPackage,
			featureDao.getTable());

	geometry2Styles.setTableStyle(GeometryType.POINT, styles.get(0));
	geometry2Styles.setTableStyle(GeometryType.LINESTRING, styles.get(1));
	geometry2Styles.setTableStyle(GeometryType.POLYGON, styles.get(0));
	geometry2Styles.setTableStyle(GeometryType.GEOMETRY, styles.get(2));

	geometry2Styles.createStyleRelationship();
	geometry2Styles.createIconRelationship();

	FeatureResultSet features = featureDao.queryForAll();
	while (features.moveToNext()) {
		FeatureRow featureRow = features.getRow();
		switch (featureRow.getGeometryType()) {
		case POINT:
			geometry2Styles.setIcon(featureRow, icons.get(0));
			break;
		case LINESTRING:
			geometry2Styles.setStyle(featureRow, styles.get(0));
			break;
		case POLYGON:
			geometry2Styles.setStyle(featureRow, styles.get(1));
			break;
		default:
		}
	}
	features.close();

}
 
Example 4
Source File: GoogleMapShapeConverterUtils.java    From geopackage-android-map with MIT License 4 votes vote down vote up
/**
 * Test shapes
 * 
 * @param geoPackage
 * @throws SQLException
 */
public static void testShapes(GeoPackage geoPackage) throws SQLException {

	GeometryColumnsDao geometryColumnsDao = geoPackage
			.getGeometryColumnsDao();

	if (geometryColumnsDao.isTableExists()) {
		List<GeometryColumns> results = geometryColumnsDao.queryForAll();

		for (GeometryColumns geometryColumns : results) {

			FeatureDao dao = geoPackage.getFeatureDao(geometryColumns);

			GoogleMapShapeConverter converter = new GoogleMapShapeConverter(
					dao.getProjection());
			converter.setExteriorOrientation(null);
			converter.setHoleOrientation(null);

			// Query for all
			FeatureCursor cursor = dao.queryForAll();
			while (cursor.moveToNext()) {
				FeatureRow featureRow = cursor.getRow();

				GeoPackageGeometryData geometryData = featureRow
						.getGeometry();

				if (geometryData != null) {
					Geometry geometry = geometryData.getGeometry();
					GeometryType geometryType = geometry.getGeometryType();

					switch (geometryType) {
					case POINT:
						convertPoint(converter, (Point) geometry);
						break;
					case LINESTRING:
						convertLineString(converter, (LineString) geometry);
						break;
					case POLYGON:
						convertPolygon(converter, (Polygon) geometry);
						break;
					case MULTIPOINT:
						convertMultiPoint(converter, (MultiPoint) geometry);
						break;
					case MULTILINESTRING:
						convertMultiLineString(converter,
								(MultiLineString) geometry);
						break;
					case MULTIPOLYGON:
						convertMultiPolygon(converter,
								(MultiPolygon) geometry);
						break;
					case CIRCULARSTRING:
						convertLineString(converter,
								(CircularString) geometry);
						break;
					case COMPOUNDCURVE:
						convertCompoundCurve(converter,
								(CompoundCurve) geometry);
						break;
					case POLYHEDRALSURFACE:
						convertMultiPolygon(converter,
								(PolyhedralSurface) geometry);
						break;
					case TIN:
						convertMultiPolygon(converter, (TIN) geometry);
						break;
					case TRIANGLE:
						convertPolygon(converter, (Triangle) geometry);
						break;
					default:
					}
				}

			}
			cursor.close();

		}
	}

}
 
Example 5
Source File: FeatureUtils.java    From geopackage-android with MIT License 4 votes vote down vote up
/**
 * Test delete
 *
 * @param geoPackage GeoPackage
 * @throws SQLException upon error
 */
public static void testDelete(GeoPackage geoPackage) throws SQLException {

    GeometryColumnsDao geometryColumnsDao = geoPackage
            .getGeometryColumnsDao();

    if (geometryColumnsDao.isTableExists()) {
        List<GeometryColumns> results = geometryColumnsDao.queryForAll();

        for (GeometryColumns geometryColumns : results) {

            FeatureDao dao = geoPackage.getFeatureDao(geometryColumns);
            TestCase.assertNotNull(dao);

            FeatureCursor cursor = dao.queryForAll();
            int count = cursor.getCount();
            if (count > 0) {

                // Choose random feature
                int random = (int) (Math.random() * count);
                cursor.moveToPosition(random);

                FeatureRow featureRow = cursor.getRow();
                cursor.close();

                // Delete row
                try {
                    TestCase.assertEquals(1, dao.delete(featureRow));
                } catch (SQLiteException e) {
                    if (TestUtils.isFutureSQLiteException(e)) {
                        continue;
                    } else {
                        throw e;
                    }
                }

                // Verify deleted
                FeatureRow queryFeatureRow = dao.queryForIdRow(featureRow
                        .getId());
                TestCase.assertNull(queryFeatureRow);
                cursor = dao.queryForAll();
                TestCase.assertEquals(count - 1, cursor.getCount());
                cursor.close();
            }
            cursor.close();
        }
    }
}
 
Example 6
Source File: GeoPackageExample.java    From geopackage-android with MIT License 4 votes vote down vote up
private static void insertRelatedTablesFeaturesExtensionRows(
        GeoPackage geoPackage, ExtendedRelation relation) {

    RelatedTablesExtension relatedTables = new RelatedTablesExtension(
            geoPackage);
    UserMappingDao userMappingDao = relatedTables.getMappingDao(relation);

    FeatureDao featureDao1 = geoPackage.getFeatureDao(relation
            .getBaseTableName());
    FeatureDao featureDao2 = geoPackage.getFeatureDao(relation
            .getRelatedTableName());

    FeatureCursor featureCursor1 = featureDao1.queryForAll();
    while (featureCursor1.moveToNext()) {

        FeatureRow featureRow1 = featureCursor1.getRow();
        String featureName = featureRow1.getValue(TEXT_COLUMN).toString();

        FeatureCursor featureCursor2 = featureDao2.queryForEq(
                TEXT_COLUMN, featureName);
        while (featureCursor2.moveToNext()) {

            FeatureRow featureRow2 = featureCursor2.getRow();

            UserMappingRow userMappingRow = userMappingDao.newRow();
            userMappingRow.setBaseId(featureRow1.getId());
            userMappingRow.setRelatedId(featureRow2.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);
        }
        featureCursor2.close();

    }
    featureCursor1.close();

}
 
Example 7
Source File: GeoPackageExample.java    From geopackage-android 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());

    FeatureCursor featureCursor = featureDao.queryForAll();
    while (featureCursor.moveToNext()) {

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

        TileCursor tileCursor = tileDao
                .queryForTile(tileDao.getMinZoom());
        while (tileCursor.moveToNext()) {

            TileRow tileRow = tileCursor.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);
        }
        tileCursor.close();

    }
    featureCursor.close();

}
 
Example 8
Source File: GeoPackageExample.java    From geopackage-android with MIT License 4 votes vote down vote up
private static void createFeatureStylesGeometry1(GeoPackage geoPackage,
                                                 List<StyleRow> styles, List<IconRow> icons) throws IOException {

    FeatureDao featureDao = geoPackage.getFeatureDao("geometry1");
    FeatureTableStyles geometry1Styles = new FeatureTableStyles(geoPackage,
            featureDao.getTable());

    geometry1Styles.setTableStyleDefault(styles.get(0));
    geometry1Styles.setTableStyle(GeometryType.POLYGON, styles.get(1));
    geometry1Styles.setTableStyle(GeometryType.POINT, styles.get(2));

    geometry1Styles.createStyleRelationship();
    geometry1Styles.createIconRelationship();

    int pointCount = 0;
    int lineCount = 0;
    int polygonCount = 0;

    FeatureCursor features = featureDao.queryForAll();
    while (features.moveToNext()) {
        FeatureRow featureRow = features.getRow();
        switch (featureRow.getGeometryType()) {
            case POINT:
                pointCount++;
                switch (pointCount) {
                    case 1:
                        geometry1Styles.setIcon(featureRow, icons.get(0));
                        break;
                    case 2:
                        geometry1Styles.setIcon(featureRow, icons.get(1));
                        break;
                    case 3:
                        geometry1Styles.setIcon(featureRow, icons.get(2));
                        break;
                }
                break;
            case LINESTRING:
                lineCount++;
                switch (lineCount) {
                    case 2:
                        geometry1Styles.setStyle(featureRow, styles.get(1));
                        break;
                    case 3:
                        geometry1Styles.setStyle(featureRow, styles.get(2));
                        break;
                }
                break;
            case POLYGON:
                polygonCount++;
                switch (polygonCount) {
                    case 2:
                        geometry1Styles.setStyle(featureRow, styles.get(3));
                        break;
                    case 3:
                        geometry1Styles.setStyle(featureRow, styles.get(2));
                        break;
                }
                break;
            default:
        }
    }
    features.close();

}
 
Example 9
Source File: GeoPackageGeometryDataUtils.java    From geopackage-android with MIT License 4 votes vote down vote up
/**
 * Test transforming geometries between projections
 *
 * @param geoPackage
 * @throws SQLException
 * @throws IOException
 */
public static void testGeometryProjectionTransform(GeoPackage geoPackage)
        throws SQLException, IOException {

    GeometryColumnsDao geometryColumnsDao = geoPackage
            .getGeometryColumnsDao();

    if (geometryColumnsDao.isTableExists()) {
        List<GeometryColumns> results = geometryColumnsDao.queryForAll();

        for (GeometryColumns geometryColumns : results) {

            FeatureDao dao = geoPackage.getFeatureDao(geometryColumns);
            TestCase.assertNotNull(dao);

            FeatureCursor cursor = dao.queryForAll();

            while (cursor.moveToNext()) {

                GeoPackageGeometryData geometryData = cursor.getGeometry();
                if (geometryData != null) {

                    Geometry geometry = geometryData.getGeometry();

                    if (geometry != null) {

                        SpatialReferenceSystemDao srsDao = geoPackage
                                .getSpatialReferenceSystemDao();
                        long srsId = geometryData.getSrsId();
                        SpatialReferenceSystem srs = srsDao
                                .queryForId(srsId);

                        long epsg = srs.getOrganizationCoordsysId();
                        Projection projection = srs.getProjection();
                        long toEpsg = -1;
                        if (epsg == ProjectionConstants.EPSG_WORLD_GEODETIC_SYSTEM) {
                            toEpsg = ProjectionConstants.EPSG_WEB_MERCATOR;
                        } else {
                            toEpsg = ProjectionConstants.EPSG_WORLD_GEODETIC_SYSTEM;
                        }
                        ProjectionTransform transformTo = projection
                                .getTransformation(toEpsg);
                        ProjectionTransform transformFrom = srs.getTransformation(transformTo
                                .getToProjection());

                        byte[] bytes = geometryData.getWkbBytes();

                        Geometry projectedGeometry = transformTo
                                .transform(geometry);
                        GeoPackageGeometryData projectedGeometryData = new GeoPackageGeometryData(
                                -1);
                        projectedGeometryData
                                .setGeometry(projectedGeometry);
                        projectedGeometryData.toBytes();
                        byte[] projectedBytes = projectedGeometryData
                                .getWkbBytes();

                        if (epsg > 0) {
                            TestCase.assertFalse(equalByteArrays(bytes,
                                    projectedBytes));
                        }

                        Geometry restoredGeometry = transformFrom
                                .transform(projectedGeometry);

                        compareGeometries(geometry, restoredGeometry, .001);
                    }
                }

            }
            cursor.close();
        }
    }
}
 
Example 10
Source File: MapFragment.java    From mage-android with Apache License 2.0 4 votes vote down vote up
/**
 * Add the GeoPackage Feature Table Cache Overlay
 * @param enabledCacheOverlays
 * @param featureTableCacheOverlay
 * @param geoPackage
 */
private void addGeoPackageFeatureCacheOverlay(Map<String, CacheOverlay> enabledCacheOverlays, GeoPackageFeatureTableCacheOverlay featureTableCacheOverlay, GeoPackage geoPackage){
	// Retrieve the cache overlay if it already exists (and remove from cache overlays)
	CacheOverlay cacheOverlay = cacheOverlays.remove(featureTableCacheOverlay.getCacheName());
	if(cacheOverlay != null){
		// If the existing cache overlay is being replaced, create a new cache overlay
		if(featureTableCacheOverlay.getParent().isAdded()){
			cacheOverlay = null;
		}
		for(GeoPackageTileTableCacheOverlay linkedTileTable: featureTableCacheOverlay.getLinkedTileTables()){
			cacheOverlays.remove(linkedTileTable.getCacheName());
		}
	}
	if(cacheOverlay == null) {
		// Add the features to the map
		FeatureDao featureDao = geoPackage.getFeatureDao(featureTableCacheOverlay.getName());

		// If indexed, add as a tile overlay
		if(featureTableCacheOverlay.isIndexed()){
			FeatureTiles featureTiles = new DefaultFeatureTiles(getActivity(), geoPackage, featureDao,
					getResources().getDisplayMetrics().density);
			Integer maxFeaturesPerTile = null;
			if(featureDao.getGeometryType() == GeometryType.POINT){
				maxFeaturesPerTile = getResources().getInteger(R.integer.geopackage_feature_tiles_max_points_per_tile);
			}else{
				maxFeaturesPerTile = getResources().getInteger(R.integer.geopackage_feature_tiles_max_features_per_tile);
			}
			featureTiles.setMaxFeaturesPerTile(maxFeaturesPerTile);
			NumberFeaturesTile numberFeaturesTile = new NumberFeaturesTile(getActivity());
			// Adjust the max features number tile draw paint attributes here as needed to
			// change how tiles are drawn when more than the max features exist in a tile
			featureTiles.setMaxFeaturesTileDraw(numberFeaturesTile);
			// Adjust the feature tiles draw paint attributes here as needed to change how
			// features are drawn on tiles
			FeatureOverlay featureOverlay = new FeatureOverlay(featureTiles);
			featureOverlay.setMinZoom(featureTableCacheOverlay.getMinZoom());

			// Get the tile linked overlay
			BoundedOverlay overlay = GeoPackageOverlayFactory.getLinkedFeatureOverlay(featureOverlay, geoPackage);

			FeatureOverlayQuery featureOverlayQuery = new FeatureOverlayQuery(getActivity(), overlay, featureTiles);
			featureTableCacheOverlay.setFeatureOverlayQuery(featureOverlayQuery);
			TileOverlayOptions overlayOptions = createFeatureTileOverlayOptions(overlay);
			TileOverlay tileOverlay = map.addTileOverlay(overlayOptions);
			featureTableCacheOverlay.setTileOverlay(tileOverlay);
		}
		// Not indexed, add the features to the map
		else {
			int maxFeaturesPerTable = 0;
			if(featureDao.getGeometryType() == GeometryType.POINT){
				maxFeaturesPerTable = getResources().getInteger(R.integer.geopackage_features_max_points_per_table);
			}else{
				maxFeaturesPerTable = getResources().getInteger(R.integer.geopackage_features_max_features_per_table);
			}
			Projection projection = featureDao.getProjection();
			GoogleMapShapeConverter shapeConverter = new GoogleMapShapeConverter(projection);
			FeatureCursor featureCursor = featureDao.queryForAll();
			try {
				final int totalCount = featureCursor.getCount();
				int count = 0;
				while (featureCursor.moveToNext()) {
					try {
						FeatureRow featureRow = featureCursor.getRow();
						GeoPackageGeometryData geometryData = featureRow.getGeometry();
						if (geometryData != null && !geometryData.isEmpty()) {
							Geometry geometry = geometryData.getGeometry();
							if (geometry != null) {
								GoogleMapShape shape = shapeConverter.toShape(geometry);
								// Set the Shape Marker, PolylineOptions, and PolygonOptions here if needed to change color and style
								featureTableCacheOverlay.addShapeToMap(featureRow.getId(), shape, map);

								if (++count >= maxFeaturesPerTable) {
									if (count < totalCount) {
										Toast.makeText(getActivity().getApplicationContext(), featureTableCacheOverlay.getCacheName()
												+ "- added " + count + " of " + totalCount, Toast.LENGTH_LONG).show();
									}
									break;
								}
							}
						}
					}catch(Exception e){
						Log.e(LOG_NAME, "Failed to display feature. GeoPackage: " + geoPackage.getName()
								+ ", Table: " + featureDao.getTableName() + ", Row: " + featureCursor.getPosition(), e);
					}
				}
			} finally {
				featureCursor.close();
			}
		}

		cacheOverlay = featureTableCacheOverlay;
	}

	// Add the cache overlay to the enabled cache overlays
	enabledCacheOverlays.put(cacheOverlay.getCacheName(), cacheOverlay);
}
 
Example 11
Source File: GeoPackageExample.java    From geopackage-java with MIT License 4 votes vote down vote up
private static void insertRelatedTablesFeaturesExtensionRows(
		GeoPackage geoPackage, ExtendedRelation relation) {

	RelatedTablesExtension relatedTables = new RelatedTablesExtension(
			geoPackage);
	UserMappingDao userMappingDao = relatedTables.getMappingDao(relation);

	FeatureDao featureDao1 = geoPackage
			.getFeatureDao(relation.getBaseTableName());
	FeatureDao featureDao2 = geoPackage
			.getFeatureDao(relation.getRelatedTableName());

	FeatureResultSet featureResultSet1 = featureDao1.queryForAll();
	while (featureResultSet1.moveToNext()) {

		FeatureRow featureRow1 = featureResultSet1.getRow();
		String featureName = featureRow1.getValue(TEXT_COLUMN).toString();

		FeatureResultSet featureResultSet2 = featureDao2
				.queryForEq(TEXT_COLUMN, featureName);
		while (featureResultSet2.moveToNext()) {

			FeatureRow featureRow2 = featureResultSet2.getRow();

			UserMappingRow userMappingRow = userMappingDao.newRow();
			userMappingRow.setBaseId(featureRow1.getId());
			userMappingRow.setRelatedId(featureRow2.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);
		}
		featureResultSet2.close();

	}
	featureResultSet1.close();

}
 
Example 12
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 13
Source File: GeoPackageExample.java    From geopackage-java with MIT License 4 votes vote down vote up
private static void createFeatureStylesGeometry1(GeoPackage geoPackage,
		List<StyleRow> styles, List<IconRow> icons) throws IOException {

	FeatureDao featureDao = geoPackage.getFeatureDao("geometry1");
	FeatureTableStyles geometry1Styles = new FeatureTableStyles(geoPackage,
			featureDao.getTable());

	geometry1Styles.setTableStyleDefault(styles.get(0));
	geometry1Styles.setTableStyle(GeometryType.POLYGON, styles.get(1));
	geometry1Styles.setTableStyle(GeometryType.POINT, styles.get(2));

	geometry1Styles.createStyleRelationship();
	geometry1Styles.createIconRelationship();

	int pointCount = 0;
	int lineCount = 0;
	int polygonCount = 0;

	FeatureResultSet features = featureDao.queryForAll();
	while (features.moveToNext()) {
		FeatureRow featureRow = features.getRow();
		switch (featureRow.getGeometryType()) {
		case POINT:
			pointCount++;
			switch (pointCount) {
			case 1:
				geometry1Styles.setIcon(featureRow, icons.get(0));
				break;
			case 2:
				geometry1Styles.setIcon(featureRow, icons.get(1));
				break;
			case 3:
				geometry1Styles.setIcon(featureRow, icons.get(2));
				break;
			}
			break;
		case LINESTRING:
			lineCount++;
			switch (lineCount) {
			case 2:
				geometry1Styles.setStyle(featureRow, styles.get(1));
				break;
			case 3:
				geometry1Styles.setStyle(featureRow, styles.get(2));
				break;
			}
			break;
		case POLYGON:
			polygonCount++;
			switch (polygonCount) {
			case 2:
				geometry1Styles.setStyle(featureRow, styles.get(3));
				break;
			case 3:
				geometry1Styles.setStyle(featureRow, styles.get(2));
				break;
			}
			break;
		default:
		}
	}
	features.close();

}
 
Example 14
Source File: GeoPackageGeometryDataUtils.java    From geopackage-java with MIT License 4 votes vote down vote up
/**
 * Test transforming geometries between projections
 * 
 * @param geoPackage
 * @throws SQLException
 * @throws IOException
 */
public static void testGeometryProjectionTransform(GeoPackage geoPackage)
		throws SQLException, IOException {

	GeometryColumnsDao geometryColumnsDao = geoPackage
			.getGeometryColumnsDao();

	if (geometryColumnsDao.isTableExists()) {
		List<GeometryColumns> results = geometryColumnsDao.queryForAll();

		for (GeometryColumns geometryColumns : results) {

			FeatureDao dao = geoPackage.getFeatureDao(geometryColumns);
			TestCase.assertNotNull(dao);

			FeatureResultSet cursor = dao.queryForAll();

			while (cursor.moveToNext()) {

				GeoPackageGeometryData geometryData = cursor.getGeometry();
				if (geometryData != null) {

					Geometry geometry = geometryData.getGeometry();

					if (geometry != null) {

						SpatialReferenceSystemDao srsDao = geoPackage
								.getSpatialReferenceSystemDao();
						long srsId = geometryData.getSrsId();
						SpatialReferenceSystem srs = srsDao
								.queryForId(srsId);

						long epsg = srs.getOrganizationCoordsysId();
						Projection projection = srs.getProjection();
						long toEpsg = -1;
						if (epsg == ProjectionConstants.EPSG_WORLD_GEODETIC_SYSTEM) {
							toEpsg = ProjectionConstants.EPSG_WEB_MERCATOR;
						} else {
							toEpsg = ProjectionConstants.EPSG_WORLD_GEODETIC_SYSTEM;
						}
						ProjectionTransform transformTo = projection
								.getTransformation(toEpsg);
						ProjectionTransform transformFrom = srs
								.getTransformation(transformTo
										.getToProjection());

						byte[] bytes = geometryData.getWkbBytes();

						Geometry projectedGeometry = transformTo
								.transform(geometry);
						GeoPackageGeometryData projectedGeometryData = new GeoPackageGeometryData(
								-1);
						projectedGeometryData
								.setGeometry(projectedGeometry);
						projectedGeometryData.toBytes();
						byte[] projectedBytes = projectedGeometryData
								.getWkbBytes();

						if (epsg > 0) {
							TestCase.assertFalse(equalByteArrays(bytes,
									projectedBytes));
						}

						Geometry restoredGeometry = transformFrom
								.transform(projectedGeometry);

						compareGeometries(geometry, restoredGeometry, .001);
					}
				}

			}
			cursor.close();
		}
	}
}