Skip to content
This repository was archived by the owner on Nov 28, 2017. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .idea/inspectionProfiles/SWAGD.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 1 addition & 14 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions GeoPackage/src/main/java/com/rgi/geopackage/GeoPackage.java
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ public GeoPackage(final File file, final VerificationLevel verificationLevel, fi
DatabaseUtility.setPragmaForeignKeys(this.databaseConnection, true);
DatabaseUtility.setPragmaJournalModeMemory(this.databaseConnection);

// this was moved below setting the pragmas because is starts a transaction and causes setPragmaSynchronousOff to throw an exception
// This was moved below the pragmas because it starts a transaction and causes setPragmaSynchronousOff to throw an exception
this.databaseConnection.setAutoCommit(false);

this.core = new GeoPackageCore (this.databaseConnection, isNewFile);
Expand Down Expand Up @@ -465,5 +465,5 @@ public enum OpenMode
private final GeoPackageMetadata metadata;
private final GeoPackageExtensions extensions;

private static final byte[] GeoPackageSqliteApplicationId = {(byte) 'G', (byte) 'P', (byte) '1', (byte) '0'};
private static final byte[] GeoPackageSqliteApplicationId = {(byte) 'G', (byte) 'P', (byte) '1', (byte) '2'};
}
36 changes: 14 additions & 22 deletions GeoPackage/src/main/java/com/rgi/geopackage/core/CoreVerifier.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
import java.io.FileInputStream;
import java.io.IOException;
import java.io.RandomAccessFile;
import java.nio.ByteBuffer;
import java.nio.charset.StandardCharsets;
import java.sql.Connection;
import java.sql.PreparedStatement;
Expand Down Expand Up @@ -153,45 +152,38 @@ public void requirement1() throws IOException, AssertionError
* Requirement 2
*
* <blockquote>
* A GeoPackage SHALL contain 0x47503130 ("GP10" in ASCII)
* in the application id field of the SQLite database header
* to indicate a GeoPackage version 1.0 file.
* A GeoPackage SHALL contain an appropriate value in the application ID
* field of the SQLite database header to indicate that it is a GeoPackage.
* The value SHALL have a prefix of 0x4750 ("GP" in ASCII). A value of
* 0x47503132 ("GP12" in ASCII) SHALL indicate a GeoPackage version 1.2 file.
* </blockquote>
* @throws AssertionError throws if it fails to meet the specified requirement;
* @throws AssertionError throws if it fails to meet the specified requirement
*/
@Requirement(reference = "Requirement 2",
text = "A GeoPackage SHALL contain 0x47503130 ('GP10' in ASCII) in the application id field of the SQLite database header to indicate a GeoPackage version 1.0 file.")
text = "A GeoPackage SHALL contain an appropriate value in the application ID field of the SQLite database header to indicate that it is a GeoPackage. The value SHALL have a prefix of 0x4750 (\"GP\" in ASCII). A value of 0x47503132 (\"GP12\" in ASCII) SHALL indicate a GeoPackage version 1.2 file.")
public void requirement2() throws AssertionError
{
final int sizeOfInt = 4;
final byte[] data = new byte[sizeOfInt]; // 4 bytes in an int
final int sizeOfPrefix = 2;
final byte[] data = new byte[sizeOfPrefix]; // 4 bytes in an int

try(RandomAccessFile randomAccessFile = new RandomAccessFile(this.file, "r"))
{
final long applicationIdByteOffset = 68;
randomAccessFile.seek(applicationIdByteOffset);
assertTrue("The file does not have enough bytes to contain a GeoPackage.",
randomAccessFile.read(data, 0, sizeOfInt) == sizeOfInt,
randomAccessFile.read(data, 0, sizeOfPrefix) == sizeOfPrefix,
Severity.Warning);
}
catch(final Exception ex)
{
throw new AssertionError(ex, Severity.Error);
}

// application id
// http://www.sqlite.org/fileformat2.html
// http://www.geopackage.org/spec/#_sqlite_container
// A GeoPackage SHALL contain 0x47503130 ("GP10" in ASCII) in the
// application id field of the SQLite database header to indicate a
// GeoPackage version 1.0 file.
// The bytes 'G', 'P', '1', '0' are equivalent to 0x47503130
final int expectedAppId = 0x47503130;

final int applicationId = ByteBuffer.wrap(data).asIntBuffer().get();

assertTrue(String.format("Bad Application ID: 0x%08x Expected: 0x%08x", applicationId, expectedAppId),
applicationId == expectedAppId,
assertTrue(String.format("Bad Application ID prefix: \"%c%c\" Expected: \"GP\"",
data[0],
data[1]),
data[0] == 'G' &&
data[1] == 'P',
Severity.Warning);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -646,7 +646,7 @@ protected void createDefaultTables() throws SQLException
// Add the default entries to the spatial reference system table
// See: http://www.geopackage.org/spec/#spatial_ref_sys -> 1.1.2.1.2. Table Data Values, Requirement 11
this.addSpatialReferenceSystemNoCommit("World Geodetic System (WGS) 1984",
1,
4326,
"EPSG",
4326,
"GEOGCS[\"WGS 84\",DATUM[\"WGS_1984\",SPHEROID[\"WGS 84\",6378137,298.257223563,AUTHORITY[\"EPSG\",\"7030\"]],AUTHORITY[\"EPSG\",\"6326\"]],PRIMEM[\"Greenwich\",0,AUTHORITY[\"EPSG\",\"8901\"]],UNIT[\"degree\",0.01745329251994328,AUTHORITY[\"EPSG\",\"9122\"]],AUTHORITY[\"EPSG\",\"4326\"]]", // http://spatialreference.org/ref/epsg/wgs-84/ogcwkt/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,6 @@

package com.rgi.geopackage.extensions;

import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.rgi.common.util.jdbc.JdbcUtility;
import com.rgi.geopackage.GeoPackage;
import com.rgi.geopackage.core.GeoPackageCore;
Expand All @@ -43,6 +33,16 @@
import com.rgi.geopackage.verification.VerificationIssue;
import com.rgi.geopackage.verification.VerificationLevel;

import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
* 'Extensions' subsystem of the {@link GeoPackage} implementation
*
Expand Down Expand Up @@ -372,7 +372,7 @@ protected String getExtensionsTableCreationSql()
"(table_name TEXT, -- Name of the table that requires the extension. When NULL, the extension is required for the entire GeoPackage. SHALL NOT be NULL when the column_name is not NULL.\n" +
" column_name TEXT, -- Name of the column that requires the extension. When NULL, the extension is required for the entire table.\n" +
" extension_name TEXT NOT NULL, -- The case sensitive name of the extension that is required, in the form <author>_<extension_name>.\n" +
" definition TEXT NOT NULL, -- Definition of the extension in the form specfied by the template in GeoPackage Extension Template (Normative) or reference thereto.\n" +
" definition TEXT NOT NULL, -- Definition of the extension in the form specified by the template in GeoPackage Extension Template (Normative) or reference thereto.\n" +
" scope TEXT NOT NULL, -- Indicates scope of extension effects on readers / writers: read-write or write-only in lowercase.\n" +
" CONSTRAINT ge_tce UNIQUE (table_name, column_name, extension_name))";
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ static ColumnDefault from(final double value)
}

/**
* Creates a string literal of the form '<string>'. Single quotes in the
* Creates a string literal of the form '&lt;string&gt;'. Single quotes in the
* string value will be escaped with an additional single quote e.g. '
* becomes ''
*
Expand All @@ -102,7 +102,7 @@ static ColumnDefault from(final String value)
}

/**
* Creates a blob literal in the form X'<hex digits>'
* Creates a blob literal in the form X'&lt;hex digits&gt;'
*
* @param value
* Array of bytes representing a binary blob
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ public void requirement18() throws AssertionError
{
final List<String> missingFeatureTables = this.contentsFeatureTableNames
.stream()
.filter(this::hasPrimaryKey)
.filter(tableName -> !this.hasPrimaryKey(tableName))
.collect(Collectors.toList());

assertTrue(String.format("The following feature table entries in the gpkg_contents table are missing or are missing a primary key column: %s",
Expand Down Expand Up @@ -364,9 +364,9 @@ private boolean isValidGeometry(final byte[] geoPackageBinaryBlob)
{
try
{
final BinaryHeader binaryHeader = new BinaryHeader(geoPackageBinaryBlob);
final BinaryHeader binaryHeader = new BinaryHeader(geoPackageBinaryBlob); // This will throw if the array length is too short to contain a header (or if it's not long enough to contain the envelope type specified)

final Geometry geometry = this.createGeometry(geoPackageBinaryBlob); // correctly encoded per ISO 13249-3 clause 5.1.46
final Geometry geometry = this.createGeometry(binaryHeader, geoPackageBinaryBlob); // correctly encoded per ISO 13249-3 clause 5.1.46

return binaryHeader.getEnvelopeContentsIndicator() != EnvelopeContentsIndicator.NoEnvelope ||
binaryHeader.getEnvelope().equals(geometry.createEnvelope());
Expand All @@ -377,10 +377,9 @@ private boolean isValidGeometry(final byte[] geoPackageBinaryBlob)
}
}

private Geometry createGeometry(final byte[] geoPackageBinaryBlob) throws WellKnownBinaryFormatException
private Geometry createGeometry(final BinaryHeader binaryHeader,
final byte[] geoPackageBinaryBlob) throws WellKnownBinaryFormatException
{
final BinaryHeader binaryHeader = new BinaryHeader(geoPackageBinaryBlob); // This will throw if the array length is too short to contain a header (or if it's not long enough to contain the envelope type specified)

if(binaryHeader.getBinaryType() == BinaryType.Standard)
{
final int headerByteLength = binaryHeader.getByteSize();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -854,17 +854,17 @@ protected void addGeometryColumnNoCommit(final String tableNam
{
this.createGeometryColumnTableNoCommit(); // Create the feature metadata table

final String insertTileMatrix = String.format("INSERT INTO %s (%s, %s, %s, %s, %s, %s) VALUES (?, ?, ?, ?, ?, ?)",
GeoPackageFeatures.GeometryColumnsTableName,
"table_name",
"column_name",
"geometry_type_name",
"srs_id",
"z",
"m");
final String insertGeometryColumn = String.format("INSERT INTO %s (%s, %s, %s, %s, %s, %s) VALUES (?, ?, ?, ?, ?, ?)",
GeoPackageFeatures.GeometryColumnsTableName,
"table_name",
"column_name",
"geometry_type_name",
"srs_id",
"z",
"m");

JdbcUtility.update(this.databaseConnection,
insertTileMatrix,
insertGeometryColumn,
preparedStatement -> { preparedStatement.setString(1, tableName);
preparedStatement.setString(2, geometryColumn.getName());
preparedStatement.setString(3, geometryColumn.getType());
Expand Down
Loading