diff --git a/build.gradle b/build.gradle index c9021b1e..dd0d11c1 100644 --- a/build.gradle +++ b/build.gradle @@ -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 @@ -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 { @@ -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 } @@ -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' diff --git a/data/gdb/TestCrash.gdb/a00000001.TablesByName.atx b/data/gdb/TestCrash.gdb/a00000001.TablesByName.atx new file mode 100755 index 00000000..56dfa17b Binary files /dev/null and b/data/gdb/TestCrash.gdb/a00000001.TablesByName.atx differ diff --git a/data/gdb/TestCrash.gdb/a00000001.gdbindexes b/data/gdb/TestCrash.gdb/a00000001.gdbindexes new file mode 100755 index 00000000..b02aa751 Binary files /dev/null and b/data/gdb/TestCrash.gdb/a00000001.gdbindexes differ diff --git a/data/gdb/TestCrash.gdb/a00000001.gdbtable b/data/gdb/TestCrash.gdb/a00000001.gdbtable new file mode 100755 index 00000000..ddf91c4d Binary files /dev/null and b/data/gdb/TestCrash.gdb/a00000001.gdbtable differ diff --git a/data/gdb/TestCrash.gdb/a00000001.gdbtablx b/data/gdb/TestCrash.gdb/a00000001.gdbtablx new file mode 100755 index 00000000..ef915a75 Binary files /dev/null and b/data/gdb/TestCrash.gdb/a00000001.gdbtablx differ diff --git a/data/gdb/TestCrash.gdb/a00000002.gdbtable b/data/gdb/TestCrash.gdb/a00000002.gdbtable new file mode 100755 index 00000000..a0af90ea Binary files /dev/null and b/data/gdb/TestCrash.gdb/a00000002.gdbtable differ diff --git a/data/gdb/TestCrash.gdb/a00000002.gdbtablx b/data/gdb/TestCrash.gdb/a00000002.gdbtablx new file mode 100755 index 00000000..7c12c568 Binary files /dev/null and b/data/gdb/TestCrash.gdb/a00000002.gdbtablx differ diff --git a/data/gdb/TestCrash.gdb/a00000003.gdbindexes b/data/gdb/TestCrash.gdb/a00000003.gdbindexes new file mode 100755 index 00000000..58df68d5 Binary files /dev/null and b/data/gdb/TestCrash.gdb/a00000003.gdbindexes differ diff --git a/data/gdb/TestCrash.gdb/a00000003.gdbtable b/data/gdb/TestCrash.gdb/a00000003.gdbtable new file mode 100755 index 00000000..d92d38fc Binary files /dev/null and b/data/gdb/TestCrash.gdb/a00000003.gdbtable differ diff --git a/data/gdb/TestCrash.gdb/a00000003.gdbtablx b/data/gdb/TestCrash.gdb/a00000003.gdbtablx new file mode 100755 index 00000000..2f80ed4f Binary files /dev/null and b/data/gdb/TestCrash.gdb/a00000003.gdbtablx differ diff --git a/data/gdb/TestCrash.gdb/a00000004.CatItemsByPhysicalName.atx b/data/gdb/TestCrash.gdb/a00000004.CatItemsByPhysicalName.atx new file mode 100755 index 00000000..80bbcfaa Binary files /dev/null and b/data/gdb/TestCrash.gdb/a00000004.CatItemsByPhysicalName.atx differ diff --git a/data/gdb/TestCrash.gdb/a00000004.CatItemsByType.atx b/data/gdb/TestCrash.gdb/a00000004.CatItemsByType.atx new file mode 100755 index 00000000..d3d48926 Binary files /dev/null and b/data/gdb/TestCrash.gdb/a00000004.CatItemsByType.atx differ diff --git a/data/gdb/TestCrash.gdb/a00000004.FDO_UUID.atx b/data/gdb/TestCrash.gdb/a00000004.FDO_UUID.atx new file mode 100755 index 00000000..fafb5fce Binary files /dev/null and b/data/gdb/TestCrash.gdb/a00000004.FDO_UUID.atx differ diff --git a/data/gdb/TestCrash.gdb/a00000004.freelist b/data/gdb/TestCrash.gdb/a00000004.freelist new file mode 100755 index 00000000..cf4d31d4 Binary files /dev/null and b/data/gdb/TestCrash.gdb/a00000004.freelist differ diff --git a/data/gdb/TestCrash.gdb/a00000004.gdbindexes b/data/gdb/TestCrash.gdb/a00000004.gdbindexes new file mode 100755 index 00000000..a4f334d7 Binary files /dev/null and b/data/gdb/TestCrash.gdb/a00000004.gdbindexes differ diff --git a/data/gdb/TestCrash.gdb/a00000004.gdbtable b/data/gdb/TestCrash.gdb/a00000004.gdbtable new file mode 100755 index 00000000..6201db4e Binary files /dev/null and b/data/gdb/TestCrash.gdb/a00000004.gdbtable differ diff --git a/data/gdb/TestCrash.gdb/a00000004.gdbtablx b/data/gdb/TestCrash.gdb/a00000004.gdbtablx new file mode 100755 index 00000000..5f2027b3 Binary files /dev/null and b/data/gdb/TestCrash.gdb/a00000004.gdbtablx differ diff --git a/data/gdb/TestCrash.gdb/a00000004.spx b/data/gdb/TestCrash.gdb/a00000004.spx new file mode 100755 index 00000000..b5fd1918 Binary files /dev/null and b/data/gdb/TestCrash.gdb/a00000004.spx differ diff --git a/data/gdb/TestCrash.gdb/a00000005.CatItemTypesByName.atx b/data/gdb/TestCrash.gdb/a00000005.CatItemTypesByName.atx new file mode 100755 index 00000000..83b7df36 Binary files /dev/null and b/data/gdb/TestCrash.gdb/a00000005.CatItemTypesByName.atx differ diff --git a/data/gdb/TestCrash.gdb/a00000005.CatItemTypesByParentTypeID.atx b/data/gdb/TestCrash.gdb/a00000005.CatItemTypesByParentTypeID.atx new file mode 100755 index 00000000..eade39f5 Binary files /dev/null and b/data/gdb/TestCrash.gdb/a00000005.CatItemTypesByParentTypeID.atx differ diff --git a/data/gdb/TestCrash.gdb/a00000005.CatItemTypesByUUID.atx b/data/gdb/TestCrash.gdb/a00000005.CatItemTypesByUUID.atx new file mode 100755 index 00000000..b428c71a Binary files /dev/null and b/data/gdb/TestCrash.gdb/a00000005.CatItemTypesByUUID.atx differ diff --git a/data/gdb/TestCrash.gdb/a00000005.gdbindexes b/data/gdb/TestCrash.gdb/a00000005.gdbindexes new file mode 100755 index 00000000..bc887093 Binary files /dev/null and b/data/gdb/TestCrash.gdb/a00000005.gdbindexes differ diff --git a/data/gdb/TestCrash.gdb/a00000005.gdbtable b/data/gdb/TestCrash.gdb/a00000005.gdbtable new file mode 100755 index 00000000..2dd59c7a Binary files /dev/null and b/data/gdb/TestCrash.gdb/a00000005.gdbtable differ diff --git a/data/gdb/TestCrash.gdb/a00000005.gdbtablx b/data/gdb/TestCrash.gdb/a00000005.gdbtablx new file mode 100755 index 00000000..15d5f440 Binary files /dev/null and b/data/gdb/TestCrash.gdb/a00000005.gdbtablx differ diff --git a/data/gdb/TestCrash.gdb/a00000006.CatRelsByDestinationID.atx b/data/gdb/TestCrash.gdb/a00000006.CatRelsByDestinationID.atx new file mode 100755 index 00000000..0d64b1a7 Binary files /dev/null and b/data/gdb/TestCrash.gdb/a00000006.CatRelsByDestinationID.atx differ diff --git a/data/gdb/TestCrash.gdb/a00000006.CatRelsByOriginID.atx b/data/gdb/TestCrash.gdb/a00000006.CatRelsByOriginID.atx new file mode 100755 index 00000000..737a2975 Binary files /dev/null and b/data/gdb/TestCrash.gdb/a00000006.CatRelsByOriginID.atx differ diff --git a/data/gdb/TestCrash.gdb/a00000006.CatRelsByType.atx b/data/gdb/TestCrash.gdb/a00000006.CatRelsByType.atx new file mode 100755 index 00000000..7d07fb2a Binary files /dev/null and b/data/gdb/TestCrash.gdb/a00000006.CatRelsByType.atx differ diff --git a/data/gdb/TestCrash.gdb/a00000006.FDO_UUID.atx b/data/gdb/TestCrash.gdb/a00000006.FDO_UUID.atx new file mode 100755 index 00000000..88007302 Binary files /dev/null and b/data/gdb/TestCrash.gdb/a00000006.FDO_UUID.atx differ diff --git a/data/gdb/TestCrash.gdb/a00000006.gdbindexes b/data/gdb/TestCrash.gdb/a00000006.gdbindexes new file mode 100755 index 00000000..c608a88b Binary files /dev/null and b/data/gdb/TestCrash.gdb/a00000006.gdbindexes differ diff --git a/data/gdb/TestCrash.gdb/a00000006.gdbtable b/data/gdb/TestCrash.gdb/a00000006.gdbtable new file mode 100755 index 00000000..504daac0 Binary files /dev/null and b/data/gdb/TestCrash.gdb/a00000006.gdbtable differ diff --git a/data/gdb/TestCrash.gdb/a00000006.gdbtablx b/data/gdb/TestCrash.gdb/a00000006.gdbtablx new file mode 100755 index 00000000..f8184c1e Binary files /dev/null and b/data/gdb/TestCrash.gdb/a00000006.gdbtablx differ diff --git a/data/gdb/TestCrash.gdb/a00000007.CatRelTypesByBackwardLabel.atx b/data/gdb/TestCrash.gdb/a00000007.CatRelTypesByBackwardLabel.atx new file mode 100755 index 00000000..3a748d2c Binary files /dev/null and b/data/gdb/TestCrash.gdb/a00000007.CatRelTypesByBackwardLabel.atx differ diff --git a/data/gdb/TestCrash.gdb/a00000007.CatRelTypesByDestItemTypeID.atx b/data/gdb/TestCrash.gdb/a00000007.CatRelTypesByDestItemTypeID.atx new file mode 100755 index 00000000..b88d71b0 Binary files /dev/null and b/data/gdb/TestCrash.gdb/a00000007.CatRelTypesByDestItemTypeID.atx differ diff --git a/data/gdb/TestCrash.gdb/a00000007.CatRelTypesByForwardLabel.atx b/data/gdb/TestCrash.gdb/a00000007.CatRelTypesByForwardLabel.atx new file mode 100755 index 00000000..806caa11 Binary files /dev/null and b/data/gdb/TestCrash.gdb/a00000007.CatRelTypesByForwardLabel.atx differ diff --git a/data/gdb/TestCrash.gdb/a00000007.CatRelTypesByName.atx b/data/gdb/TestCrash.gdb/a00000007.CatRelTypesByName.atx new file mode 100755 index 00000000..adfcb26e Binary files /dev/null and b/data/gdb/TestCrash.gdb/a00000007.CatRelTypesByName.atx differ diff --git a/data/gdb/TestCrash.gdb/a00000007.CatRelTypesByOriginItemTypeID.atx b/data/gdb/TestCrash.gdb/a00000007.CatRelTypesByOriginItemTypeID.atx new file mode 100755 index 00000000..38e347c1 Binary files /dev/null and b/data/gdb/TestCrash.gdb/a00000007.CatRelTypesByOriginItemTypeID.atx differ diff --git a/data/gdb/TestCrash.gdb/a00000007.CatRelTypesByUUID.atx b/data/gdb/TestCrash.gdb/a00000007.CatRelTypesByUUID.atx new file mode 100755 index 00000000..a6a84493 Binary files /dev/null and b/data/gdb/TestCrash.gdb/a00000007.CatRelTypesByUUID.atx differ diff --git a/data/gdb/TestCrash.gdb/a00000007.gdbindexes b/data/gdb/TestCrash.gdb/a00000007.gdbindexes new file mode 100755 index 00000000..2a98c93a Binary files /dev/null and b/data/gdb/TestCrash.gdb/a00000007.gdbindexes differ diff --git a/data/gdb/TestCrash.gdb/a00000007.gdbtable b/data/gdb/TestCrash.gdb/a00000007.gdbtable new file mode 100755 index 00000000..9525bc18 Binary files /dev/null and b/data/gdb/TestCrash.gdb/a00000007.gdbtable differ diff --git a/data/gdb/TestCrash.gdb/a00000007.gdbtablx b/data/gdb/TestCrash.gdb/a00000007.gdbtablx new file mode 100755 index 00000000..a499848f Binary files /dev/null and b/data/gdb/TestCrash.gdb/a00000007.gdbtablx differ diff --git a/data/gdb/TestCrash.gdb/a00000009.gdbindexes b/data/gdb/TestCrash.gdb/a00000009.gdbindexes new file mode 100755 index 00000000..c9d0caa2 Binary files /dev/null and b/data/gdb/TestCrash.gdb/a00000009.gdbindexes differ diff --git a/data/gdb/TestCrash.gdb/a00000009.gdbtable b/data/gdb/TestCrash.gdb/a00000009.gdbtable new file mode 100755 index 00000000..fe87a3d8 Binary files /dev/null and b/data/gdb/TestCrash.gdb/a00000009.gdbtable differ diff --git a/data/gdb/TestCrash.gdb/a00000009.gdbtablx b/data/gdb/TestCrash.gdb/a00000009.gdbtablx new file mode 100755 index 00000000..6cdce1ac Binary files /dev/null and b/data/gdb/TestCrash.gdb/a00000009.gdbtablx differ diff --git a/data/gdb/TestCrash.gdb/a00000009.spx b/data/gdb/TestCrash.gdb/a00000009.spx new file mode 100755 index 00000000..7a5af232 Binary files /dev/null and b/data/gdb/TestCrash.gdb/a00000009.spx differ diff --git a/data/gdb/TestCrash.gdb/a0000000a.gdbindexes b/data/gdb/TestCrash.gdb/a0000000a.gdbindexes new file mode 100755 index 00000000..c9d0caa2 Binary files /dev/null and b/data/gdb/TestCrash.gdb/a0000000a.gdbindexes differ diff --git a/data/gdb/TestCrash.gdb/a0000000a.gdbtable b/data/gdb/TestCrash.gdb/a0000000a.gdbtable new file mode 100755 index 00000000..49e91275 Binary files /dev/null and b/data/gdb/TestCrash.gdb/a0000000a.gdbtable differ diff --git a/data/gdb/TestCrash.gdb/a0000000a.gdbtablx b/data/gdb/TestCrash.gdb/a0000000a.gdbtablx new file mode 100755 index 00000000..f9ee051f Binary files /dev/null and b/data/gdb/TestCrash.gdb/a0000000a.gdbtablx differ diff --git a/data/gdb/TestCrash.gdb/a0000000a.spx b/data/gdb/TestCrash.gdb/a0000000a.spx new file mode 100755 index 00000000..aca87311 Binary files /dev/null and b/data/gdb/TestCrash.gdb/a0000000a.spx differ diff --git a/data/gdb/TestCrash.gdb/gdb b/data/gdb/TestCrash.gdb/gdb new file mode 100755 index 00000000..a786e127 Binary files /dev/null and b/data/gdb/TestCrash.gdb/gdb differ diff --git a/data/gdb/TestCrash.gdb/timestamps b/data/gdb/TestCrash.gdb/timestamps new file mode 100755 index 00000000..06f9607d Binary files /dev/null and b/data/gdb/TestCrash.gdb/timestamps differ diff --git a/filegdb/filegdb/row.cpp b/filegdb/filegdb/row.cpp index bfeb0f0e..aee68fd8 100644 --- a/filegdb/filegdb/row.cpp +++ b/filegdb/filegdb/row.cpp @@ -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; @@ -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; diff --git a/src/main/java/org/opensextant/giscore/filegdb/DatasetDefinition.java b/src/main/java/org/opensextant/giscore/filegdb/DatasetDefinition.java new file mode 100644 index 00000000..90fb42f2 --- /dev/null +++ b/src/main/java/org/opensextant/giscore/filegdb/DatasetDefinition.java @@ -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; + } + +} diff --git a/src/main/java/org/opensextant/giscore/filegdb/Row.java b/src/main/java/org/opensextant/giscore/filegdb/Row.java index a879b523..2342b7e8 100755 --- a/src/main/java/org/opensextant/giscore/filegdb/Row.java +++ b/src/main/java/org/opensextant/giscore/filegdb/Row.java @@ -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; @@ -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}; + } } /** diff --git a/src/main/java/org/opensextant/giscore/filegdb/Table.java b/src/main/java/org/opensextant/giscore/filegdb/Table.java index 1179c545..2f3005f0 100644 --- a/src/main/java/org/opensextant/giscore/filegdb/Table.java +++ b/src/main/java/org/opensextant/giscore/filegdb/Table.java @@ -17,11 +17,16 @@ * ***************************************************************************************/ 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 @@ -29,7 +34,11 @@ * @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; @@ -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); @@ -126,7 +135,22 @@ public Map 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: *