Permalink
Browse files

support GeoPackage (--dbfile file.gpkg)

This code has been funded by the Canton of Solothurn (Switzerland)
  • Loading branch information...
claeis
claeis committed Jan 4, 2016
1 parent 134bea5 commit 85d167e0c4fd491567cd8e8bab3bd9f8e7a85eed
@@ -0,0 +1,123 @@
<?xml version="1.0" encoding="UTF-8"?>
<project basedir="." default="jar" name="ili2gpkg">

<!-- set global properties for this build -->
<property name="src" value="${basedir}/src"/>
<property name="build" value="${basedir}/build"/>
<property name="dist" value="${basedir}/dist"/>

<target name="init">
<!-- Create the time stamp -->
<tstamp/>
<property name="projectjar" value="${build}/jar/${ant.project.name}.jar"/>
<!-- Create the build directory structure used by compile -->
<mkdir dir="${build}"/>
<mkdir dir="${build}/jar"/>
<mkdir dir="${dist}"/>
</target>

<target depends="init" name="compile">
<!-- Compile the java code from ${src} into ${build}/classes -->
<mkdir dir="${build}/classes"/>
<javac destdir="${build}/classes" includes="**/*.java" excludes="**/test/*.java" source="1.6" target="1.6">
<classpath>
<pathelement location="lib/ehisqlgen.jar"/>
<pathelement location="lib/ili2c.jar"/>
<pathelement location="lib/jts-1.13.jar"/>
<pathelement location="lib/jdbm-2.4.jar"/>
<pathelement location="lib/sqlite-jdbc-3.8.11.2.jar"/>
</classpath>
<src path="${src}" />
<src path="ili2gpkg/src"/>
</javac>
</target>


<target depends="init" name="javadocs">
<mkdir dir="${build}/javadoc/api"/>
<javadoc Public="true" Windowtitle="${ant.project.name}" destdir="${build}/javadoc/api">
<sourcepath path="${src}"/>
</javadoc>
</target>


<target depends="init,compile" name="jar">
<propertyfile file="ili2gpkg/src/ch/ehi/ili2gpkg/Version.properties">
<!-- <entry key="versionMicro" type="int" value="1" operation="+"/> -->
<entry key="versionDate" type="date" value="now" pattern="yyyyMMdd"/>
</propertyfile>

<delete file="${projectjar}" quiet="true"/>

<jar jarfile="${projectjar}" manifest="other/manifest-ili2gpkg">
<fileset dir="${build}/classes" includes="**/*.class"/>
<fileset dir="${src}" includes="**/*.properties"/>
<fileset dir="ili2gpkg/src" includes="**/*.properties"/>
<!-- <fileset dir="resources/de" includes="**/*.properties"/>
<fileset dir="resources/fr" includes="**/*.properties"/>
<fileset dir="resources/it" includes="**/*.properties"/> -->
<fileset dir="${src}" includes="**/*.gif"/>
<fileset dir="${src}" includes="**/*.jpg"/>
<fileset dir="${src}" includes="**/*.png"/>
<zipfileset src="lib/ehisqlgen.jar"/>
<zipfileset src="lib/jts-1.13.jar"/>
<zipfileset src="lib/jdbm-2.4.jar"/>
</jar>
</target>

<target depends="init" name="buildnr">
<property file="ili2gpkg/src/ch/ehi/ili2gpkg/Version.properties" prefix="buildnr."/>
<property name="buildnr" value="${buildnr.versionMajor}.${buildnr.versionMinor}.${buildnr.versionMicro}"/>
<!-- <property name="buildnr" value="${DSTAMP}"/> -->
</target>

<target depends="init,buildnr" name="bindist">
<delete file="${dist}/${ant.project.name}-${buildnr}.zip" quiet="true"/>
<zip zipfile="${dist}/${ant.project.name}-${buildnr}.zip">
<zipfileset dir="${build}/jar" prefix="${ant.project.name}-${buildnr}">
<patternset includes="${ant.project.name}.jar"/>
</zipfileset>
<zipfileset dir="${basedir}/lib" prefix="${ant.project.name}-${buildnr}">
<patternset includes="ili2c.jar"/>
<patternset includes="sqlite-jdbc-3.8.11.2.jar"/>
</zipfileset>
<zipfileset dir="." prefix="${ant.project.name}-${buildnr}">
<patternset includes="docs/ili2pg.docx"/>
</zipfileset>
<!-- <zipfileset dir="." prefix="${ant.project.name}-${buildnr}">
<patternset includes="lib/**"/>
<patternset includes="docs/LICENSE.*"/>
<patternset includes="docs/README.txt"/>
<patternset includes="docs/CHANGELOG.txt"/>
<patternset includes="docs/ili2ora/ili2ora05.ili"/>
<patternset includes="docs/ili2ora/MappingConfig.jpeg"/>
<patternset includes="sample/zpl/**"/>
</zipfileset> -->
</zip>
</target>
<target depends="init,buildnr" name="srcdist">
<delete file="${dist}/${ant.project.name}-${buildnr}.src.zip" quiet="true"/>
<zip zipfile="${dist}/${ant.project.name}-${buildnr}.src.zip">
<zipfileset dir="." prefix="${ant.project.name}-${buildnr}">
<patternset includes="build-ili2gpkg.xml"/>
<!-- <patternset includes="lib/**"/> -->
<patternset includes="other/manifest-ili2gpkg"/>
<patternset includes="sample/zpl/**"/>
<patternset includes="src/**" excludes="**/CVS/*;**/bak~/*"/>
<patternset includes="ili2gpkg/src/**" excludes="**/CVS/*;**/bak~/*"/>
<patternset includes="resources/de/**/*.properties"/>
<patternset includes="resources/fr/**/*.properties"/>
<patternset includes="resources/it/**/*.properties"/>
<patternset includes="lib/ili2c.jar"/>
<patternset includes="lib/ehisqlgen.jar"/>
<patternset includes="lib/jts-1.13.jar"/>
<patternset includes="lib/jdbm-2.4.jar"/>
<patternset includes="lib/sqlite-jdbc-3.8.11.2.jar"/>
</zipfileset>
</zip>
</target>
<target name="clean">
<delete dir="${build}"/>
</target>

</project>
@@ -9,9 +9,12 @@ ideas/open issues/questions
- --logValidOverlaps
- support ili2 views
- --initNameMapping
- support geopackage
- map simple unique constraints

ili2gpkg 2.5.1 (2016-01-xx)
----------------------------
- support GeoPackage (--dbfile file.gpkg)

ili2pg 2.5.0 (2015-12-23)
----------------------------
- ili-obj/sql-record conversion refactored
@@ -1,6 +1,9 @@
package ch.ehi.ili2geodb;

import java.sql.Connection;

import ch.ehi.ili2db.fromili.CustomMapping;
import ch.ehi.ili2db.gui.Config;
import ch.ehi.sqlgen.repository.DbColumn;
import ch.ehi.sqlgen.repository.DbTable;
import ch.ehi.sqlgen.repository.DbTableName;
@@ -11,13 +14,13 @@
private java.util.HashMap geodbDomains=new java.util.HashMap(); // map<String geodbDomainName,AttributeDef | DomainDef>
private java.util.HashSet geodbLinks=new java.util.HashSet(); // map<GeodbLink>
@Override
public void init(ch.ehi.ili2db.gui.Config config)
public void fromIliInit(ch.ehi.ili2db.gui.Config config)
{

}

@Override
public void end(ch.ehi.ili2db.gui.Config config)
public void fromIliEnd(ch.ehi.ili2db.gui.Config config)
{
config.setTransientObject(ch.ehi.ili2geodb.sqlgen.GeodbGenerator.GEODB_DOMAINS,geodbDomains);
config.setTransientObject(ch.ehi.ili2geodb.sqlgen.GeodbGenerator.GEODB_LINKS,geodbLinks);
@@ -86,4 +89,12 @@ public void fixupEmbeddedLink(DbTable dbTable,DbColumn dbFk,AssociationDef assoc
));
}

@Override
public void preConnect(String url, String dbusr, String dbpwd, Config config) {
}

@Override
public void postConnect(Connection conn, Config config) {
}

}
@@ -11,7 +11,7 @@
import com.esri.arcgis.system.EngineInitializer;
import com.esri.arcgis.system.AoInitialize;

public class InitAOEngine implements ch.ehi.ili2db.base.Ili2dbInit {
public class InitAOEngine implements ch.ehi.ili2db.base.Ili2dbLibraryInit {
private static int refc=0;
static AoInitialize aoInitializer = null;
public void init()
@@ -0,0 +1,116 @@
/*
* The JTS Topology Suite is a collection of Java classes that
* implement the fundamental operations required to validate a given
* geo-spatial data set to a known topological specification.
*
* Copyright (C) 2001 Vivid Solutions
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* For more information, contact:
*
* Vivid Solutions
* Suite #1A
* 2328 Government Street
* Victoria BC V8T 5G5
* Canada
*
* (250)385-6040
* www.vividsolutions.com
*/
package ch.ehi.ili2gpkg;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;

import ch.ehi.ili2db.base.IliNames;
import ch.interlis.iom.IomObject;
import ch.interlis.iox_j.wkb.Wkb2iox;

import com.vividsolutions.jts.io.ByteOrderDataInStream;
import com.vividsolutions.jts.io.ByteArrayInStream;
import com.vividsolutions.jts.io.InStream;
import com.vividsolutions.jts.io.ParseException;
import com.vividsolutions.jts.io.ByteOrderValues;


public class Gpkg2iox
{

Wkb2iox helper=new Wkb2iox();

public Gpkg2iox() {
}


/**
* Reads a single {@link Geometry} from a byte array.
*
* @param bytes the byte array to read from
* @return the geometry read
* @throws ParseException if a parse exception occurs
*/
public IomObject read(byte[] bytes) throws ParseException
{
// GeoPackageBinaryHeader {
// byte[2] magic = 0x4750; // ‘GP’
// byte version; // 8-bit unsigned integer, 0 = version 1
// byte flags; // see flags layout below
// int32 srs_id;
// double[] envelope; // see flags envelope contents indicator code below
//}
// magic
//os.write(0x47);
//os.write(0x50);
int pos=0;
byte magic1=bytes[pos++];
if(magic1!=0x47){
throw new ParseException("unexpected magic1 "+magic1);
}
byte magic2=bytes[pos++];
if(magic2!=0x50){
throw new ParseException("unexpected magic2 "+magic2);
}
// version os.write(0);
byte version=bytes[pos++];
if(version!=0){
throw new ParseException("unexpected version "+version);
}
// flags
byte flags=bytes[pos++];
int env=(flags & 0x0e)>>1;
int envlen=0;
if(env==0){
envlen=0;
}else if(env==1){
envlen=32;
}else if(env==2){
envlen=48;
}else if(env==3){
envlen=48;
}else if(env==4){
envlen=64;
}else{
throw new ParseException("unexpected envelope "+env);
}

// srs_id
pos+=Integer.SIZE/8;
// envelope
pos+=envlen;
return helper.read(Arrays.copyOfRange(bytes, pos, bytes.length));
}
}
Oops, something went wrong.

0 comments on commit 85d167e

Please sign in to comment.