Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Coord xform #7

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
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
11 changes: 8 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ apply plugin: 'maven'
apply plugin: 'signing'

group = 'org.opensextant'
version = '2.0.2-SNAPSHOT'
version = '2.0.3-SNAPSHOT'
ext.isReleaseVersion = !version.endsWith('-SNAPSHOT')
sourceCompatibility = 1.6

Expand All @@ -22,9 +22,10 @@ if (project.hasProperty('ospubLocaldest')) {
ext.publish.password = project.hasProperty('ospubPassword') ? ospubPassword : null
}
def oss_staging = "https://oss.sonatype.org/service/local/staging/deploy/maven2/"
def osgeo = "http://download.osgeo.org/webdav/geotools/"

repositories {
[ mavenCentral(), maven { url oss_snapshot } ]
[ mavenCentral(), maven { url oss_snapshot }, maven { url osgeo } ]
}

buildscript {
Expand Down Expand Up @@ -175,7 +176,8 @@ jar {

artifacts {
archives jar
archives javadocJar
//this fails with many errors & warnings using gradle 2.2.1
//archives javadocJar
archives sourcesJar
}

Expand All @@ -187,6 +189,9 @@ signing {
dependencies {
def slf4j_version = '1.7.2'

compile("org.geotools:gt-shapefile:12.1") {
exclude group: 'javax.media'
}
compile group: 'org.opensextant', name: 'geodesy', version: '[2.0.0,2.1)'
compile group: 'commons-lang', name: 'commons-lang', version: '2.5'
compile group: 'commons-io', name: 'commons-io', version: '1.4'
Expand Down
Binary file added data/gdb/TestCrash.gdb/a00000001.TablesByName.atx
Binary file not shown.
Binary file added data/gdb/TestCrash.gdb/a00000001.gdbindexes
Binary file not shown.
Binary file added data/gdb/TestCrash.gdb/a00000001.gdbtable
Binary file not shown.
Binary file added data/gdb/TestCrash.gdb/a00000001.gdbtablx
Binary file not shown.
Binary file added data/gdb/TestCrash.gdb/a00000002.gdbtable
Binary file not shown.
Binary file added data/gdb/TestCrash.gdb/a00000002.gdbtablx
Binary file not shown.
Binary file added data/gdb/TestCrash.gdb/a00000003.gdbindexes
Binary file not shown.
Binary file added data/gdb/TestCrash.gdb/a00000003.gdbtable
Binary file not shown.
Binary file added data/gdb/TestCrash.gdb/a00000003.gdbtablx
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added data/gdb/TestCrash.gdb/a00000004.FDO_UUID.atx
Binary file not shown.
Binary file added data/gdb/TestCrash.gdb/a00000004.freelist
Binary file not shown.
Binary file added data/gdb/TestCrash.gdb/a00000004.gdbindexes
Binary file not shown.
Binary file added data/gdb/TestCrash.gdb/a00000004.gdbtable
Binary file not shown.
Binary file added data/gdb/TestCrash.gdb/a00000004.gdbtablx
Binary file not shown.
Binary file added data/gdb/TestCrash.gdb/a00000004.spx
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added data/gdb/TestCrash.gdb/a00000005.gdbindexes
Binary file not shown.
Binary file added data/gdb/TestCrash.gdb/a00000005.gdbtable
Binary file not shown.
Binary file added data/gdb/TestCrash.gdb/a00000005.gdbtablx
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added data/gdb/TestCrash.gdb/a00000006.FDO_UUID.atx
Binary file not shown.
Binary file added data/gdb/TestCrash.gdb/a00000006.gdbindexes
Binary file not shown.
Binary file added data/gdb/TestCrash.gdb/a00000006.gdbtable
Binary file not shown.
Binary file added data/gdb/TestCrash.gdb/a00000006.gdbtablx
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added data/gdb/TestCrash.gdb/a00000007.gdbindexes
Binary file not shown.
Binary file added data/gdb/TestCrash.gdb/a00000007.gdbtable
Binary file not shown.
Binary file added data/gdb/TestCrash.gdb/a00000007.gdbtablx
Binary file not shown.
Binary file added data/gdb/TestCrash.gdb/a00000009.gdbindexes
Binary file not shown.
Binary file added data/gdb/TestCrash.gdb/a00000009.gdbtable
Binary file not shown.
Binary file added data/gdb/TestCrash.gdb/a00000009.gdbtablx
Binary file not shown.
Binary file added data/gdb/TestCrash.gdb/a00000009.spx
Binary file not shown.
Binary file added data/gdb/TestCrash.gdb/a0000000a.gdbindexes
Binary file not shown.
Binary file added data/gdb/TestCrash.gdb/a0000000a.gdbtable
Binary file not shown.
Binary file added data/gdb/TestCrash.gdb/a0000000a.gdbtablx
Binary file not shown.
Binary file added data/gdb/TestCrash.gdb/a0000000a.spx
Binary file not shown.
Binary file added data/gdb/TestCrash.gdb/gdb
Binary file not shown.
Binary file added data/gdb/TestCrash.gdb/timestamps
Binary file not shown.
5 changes: 3 additions & 2 deletions filegdb/filegdb/row.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,8 @@ JNIEXPORT jobjectArray JNICALL Java_org_opensextant_giscore_filegdb_Row_getAttrA
int count;
fieldInfo->GetFieldCount(count);
jclass oclass = me.findClass("java.lang.Object");
jclass calclass = me.findClass("java.util.GregorianCalendar");
jclass calclass = me.findClass("java.util.Calendar");
jmethodID ccgetinstance = env->GetStaticMethodID(calclass, "getInstance", "()Ljava/util/Calendar;");
jmethodID ccsetTime = me.getMethod(calclass, "setTimeInMillis", "(J)V");
jobjectArray rval = env->NewObjectArray(count * 2, oclass, 0L);
int ptr = 0;
Expand Down Expand Up @@ -361,7 +362,7 @@ JNIEXPORT jobjectArray JNICALL Java_org_opensextant_giscore_filegdb_Row_getAttrA
tm date;
row->GetDate(fieldName, date);
time_t dtm = mktime(&date);
jobject cal = env->AllocObject(calclass);
jobject cal = env->CallStaticObjectMethod(calclass, ccgetinstance);
env->CallVoidMethod(cal, ccsetTime, me.newLong(1000 * dtm));
val = cal;
break;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package org.opensextant.giscore.filegdb;

import org.geotools.referencing.CRS;
import org.geotools.referencing.crs.DefaultGeographicCRS;
import org.opengis.referencing.FactoryException;
import org.opengis.referencing.crs.CoordinateReferenceSystem;
import org.w3c.dom.Node;
import org.xml.sax.InputSource;

import javax.xml.xpath.XPath;
import javax.xml.xpath.XPathConstants;
import javax.xml.xpath.XPathFactory;
import java.io.StringReader;

public class DatasetDefinition {

private CoordinateReferenceSystem coordinateReferenceSystem = DefaultGeographicCRS.WGS84;
private String definition;

public DatasetDefinition(String definition) {
if (null == definition) {
return;
}
this.definition = definition;
setCRS();
}

public CoordinateReferenceSystem getCRS() {
return coordinateReferenceSystem;
}

private void setCRS() {
try {
String wkt = getNode("/*/SpatialReference/WKT");
if (wkt != null) {
coordinateReferenceSystem = CRS.parseWKT(wkt);
}
} catch (FactoryException e) {
e.printStackTrace();
}
}


private String getNode(String path) {
XPath xpath = XPathFactory.newInstance().newXPath();
InputSource inputSource = new InputSource(new StringReader(definition));
try {
Node node = (Node) xpath.evaluate(path, inputSource, XPathConstants.NODE);
if (node == null) {
return null;
}
return node.getTextContent();
} catch (Exception e) {
e.printStackTrace();
}
return null;
}

}
27 changes: 22 additions & 5 deletions src/main/java/org/opensextant/giscore/filegdb/Row.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
import java.util.Map;

import org.apache.commons.lang.mutable.MutableInt;
import org.opengis.referencing.operation.MathTransform;
import org.opengis.referencing.operation.TransformException;
import org.opensextant.giscore.geometry.Geometry;
import org.opensextant.giscore.geometry.Line;
import org.opensextant.giscore.geometry.LinearRing;
Expand Down Expand Up @@ -159,14 +161,29 @@ private Point getPoint(MutableInt ptr, Object[] shapeInfo, boolean hasz) {
ptr.increment();
Double lat = (Double) shapeInfo[ptr.intValue()];
ptr.increment();
double[] transformedLongLat = transform(lon, lat);
Double elev = 0.0;
if (hasz) {
Double elev = (Double) shapeInfo[ptr.intValue()];
elev = (Double) shapeInfo[ptr.intValue()];
ptr.increment();
return new Point(lat, lon, elev);
} else {
return new Point(lat, lon, 0.0);
}

return new Point(transformedLongLat[1], transformedLongLat[0], elev);
}

private double[] transform(Double lon, Double lat) {
MathTransform transform = table.getTransform();
if (transform == null) {
return new double[]{lon, lat};
}
double[] longLat = {lon, lat};
double[] transformedLongLat = {lon, lat};
try {
transform.transform(longLat, 0, transformedLongLat, 0, 1);
return transformedLongLat;
} catch (TransformException e) {
e.printStackTrace();
return new double[]{lon, lat};
}
}

/**
Expand Down
36 changes: 30 additions & 6 deletions src/main/java/org/opensextant/giscore/filegdb/Table.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,28 @@
*
***************************************************************************************/
package org.opensextant.giscore.filegdb;

import java.util.HashMap;
import java.util.Map;

import org.apache.commons.lang.StringUtils;
import org.geotools.referencing.CRS;
import org.geotools.referencing.crs.DefaultGeographicCRS;
import org.geotools.referencing.operation.transform.IdentityTransform;
import org.opengis.referencing.FactoryException;
import org.opengis.referencing.operation.MathTransform;

/**
* A table represents a dataset or a feature class
*
* @author DRAND
*
*/
public class Table extends GDB {
public class Table extends GDB {

private DatasetDefinition datasetDefinition;
private MathTransform transform;

public static class FieldInfo {
public int type;
public int length;
Expand Down Expand Up @@ -90,12 +99,12 @@ public static Table openTable(Geodatabase db, String parentpath) {
/**
* Add the given row to the table
* @param row
*/
*/
public native void add(Row row);

/**
* @return all the rows in the table as an iterator
*/
*/
public EnumRows enumerate() {
EnumRows rval = enumerate1();
rval.setTable(this);
Expand Down Expand Up @@ -126,7 +135,22 @@ public Map<String, FieldInfo> getFieldTypes() {
}
return fieldInfo;
}


public void loadDatasetDefinition(String definition) {
datasetDefinition = new DatasetDefinition(definition);
try {
transform = CRS.findMathTransform(datasetDefinition.getCRS(), DefaultGeographicCRS.WGS84, true);
} catch (FactoryException e) {
e.printStackTrace();
transform = null;
}
}

public MathTransform getTransform() {
return transform;

}

/**
* Get field information as an array of values in the following order:
* <ul>
Expand Down Expand Up @@ -167,5 +191,5 @@ public void close() {
/**
* Cleanup
*/
private native void close1();
private native void close1();
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
import org.opensextant.giscore.events.IGISObject;
import org.opensextant.giscore.events.Schema;
import org.opensextant.giscore.events.SimpleField;
import org.opensextant.giscore.filegdb.DatasetDefinition;
import org.opensextant.giscore.filegdb.EnumRows;
import org.opensextant.giscore.filegdb.Geodatabase;
import org.opensextant.giscore.filegdb.Row;
Expand All @@ -69,7 +70,7 @@ private class TableState {
private Table currentTable;
private EnumRows rows;
private Schema currentSchema;

public TableState(boolean hasGeo, List<String> paths) {
this.hasGeo = hasGeo;
this.paths = paths;
Expand Down Expand Up @@ -108,11 +109,13 @@ private IGISObject next() {
index++;
fcPath = paths.get(index);
currentSchema = getSchema(fcPath);

if (acceptor != null && !acceptor.accept(currentSchema)) {
currentSchema = null;
return next();
}
currentTable = database.openTable(fcPath);
currentTable.loadDatasetDefinition(database.getDatasetDefinition(fcPath, Geodatabase.FEATURE_CLASS));
rows = currentTable.enumerate();
ContainerStart cs = new ContainerStart("Folder");
cs.setSchema(currentSchema.getId());
Expand Down Expand Up @@ -254,7 +257,7 @@ public FileGdbInputStream(File path, Object[] args) {
IAcceptSchema acceptor = (IAcceptSchema) argv.get(IAcceptSchema.class, 0);
inputPath = path;
database = new Geodatabase(inputPath);

init(acceptor);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,11 @@ private static LinearRing makeRing(int count, double radius, double xoffset, dou

@Test
public void testReadFeatureGdb() throws IOException {
File path = new File("data/gdb/ftest1.gdb");
readGdb("data/gdb/ftest1.gdb");
}

private void readGdb(String pathname) throws IOException {
File path = new File(pathname);
IGISInputStream os = null;
try {
os = new FileGdbInputStream(path, null);
Expand Down Expand Up @@ -289,6 +293,11 @@ public void testReadFeatureGdb() throws IOException {
}
}

@Test
public void testReadCrashGdb() throws IOException {
readGdb("data/gdb/TestCrash.gdb");
}

private static void deleteGdbFolder(File db) {
if (db.exists()) {
for(File f : db.listFiles()) {
Expand Down