Attach shapefile on Android

classic Classic list List threaded Threaded
9 messages Options
Reply | Threaded
Open this post in threaded view
|

Attach shapefile on Android

moovida
Dear all,
should it be possible to attach a shapefile to h2gis onn android?

I am trying it out with: CALL FILE_TABLE('/path/to.shp', 'tableName');
but while the other spatial operations seem to work (hence I assume everything is properly initialized), attaching a shp doesn't and I get no errormessage or exception, so I am not sure.

Thanks for any hint.

Regards,
Andrea
Reply | Threaded
Open this post in threaded view
|

Re: Attach shapefile on Android

nicolas-f
Administrator
Hi,

Sorry for the delay, I finally recovered my account for this forum..

I can't help you on this side right now, We have almost done nothing on the Android system, there is none unit test on this system either.

You will have to run in step by step debug mode using the emulator or an Android phone.

regards,

Nicolas Fortin
Reply | Threaded
Open this post in threaded view
|

Re: Attach shapefile on Android

ebocher
Administrator
Dear Andrea,

Feel free to post the error message or any bug on the github account. We will try to solve  it and help you as we can.

Cheers

Erwan
Reply | Threaded
Open this post in threaded view
|

Re: Attach shapefile on Android

moovida
Thanks for the replies.

The problem I have is that I get no error at all. The query execution simply returns 0 when the CALL is done and nothing else happens.

I am already debugging this until the borders of h2gis, you are suggesting I go further, right? I am not sure I could understand anything down there :-)

Maybe I open an issue on github, perhaps anyone has suggestions.

Anyways, already with attached shapefiles it looks like I will be able to add it as a supported spatial db format for geopaparazzi, that is quite cool.

Cheers,
Andrea
Reply | Threaded
Open this post in threaded view
|

Re: Attach shapefile on Android

nicolas-f
Administrator
If you want to read supported file formats of H2GIS you can also skip the database thing. This class is not related to JDBC and is quite simple to use:

https://github.com/orbisgis/h2gis/blob/master/h2gis-functions/src/main/java/org/h2gis/functions/io/shp/internal/SHPDriver.java
Reply | Threaded
Open this post in threaded view
|

Re: Attach shapefile on Android

moovida
Hi Nicolas,
I will try that out for sure. Maybe it gives insight on why it fails when going through h2gis? I assume it uses the same driver in some background magic.

Thanks!
Andrea
Reply | Threaded
Open this post in threaded view
|

Re: Attach shapefile on Android

moovida
Ok, I have the problem.

I gave the shp driver a try and I get this exception (actually now I get the same from the CALL statement when trying to attach):

 Caused by: java.lang.NoClassDefFoundError: org.h2gis.functions.io.shp.internal.SHPDriver$1
     at org.h2gis.functions.io.shp.internal.SHPDriver.initDriverFromFile(SHPDriver.java:155)
     at org.h2gis.functions.io.shp.SHPEngine.createDriver(SHPEngine.java:47)
     at org.h2gis.functions.io.shp.SHPEngine.createDriver(SHPEngine.java:42)
     at org.h2gis.functions.io.file_table.FileEngine.createTable(FileEngine.java:60)
     at org.h2.schema.Schema.createTable(Schema.java:590)
     at org.h2.command.ddl.CreateTable.update(CreateTable.java:137)
     at org.h2.command.CommandContainer.update(CommandContainer.java:98)
     at org.h2.command.Command.executeUpdate(Command.java:258)

This is due to the fact that the driver uses some files that probably are not part of the Android JVM as for example:
import java.nio.file.DirectoryStream;
import java.nio.file.Files;
import java.nio.file.Path;

So I guess the h2gis libs are not an option in the current state.

Andrea
Reply | Threaded
Open this post in threaded view
|

Re: Attach shapefile on Android

moovida
I confirm that by substituting just the sidecar file searching using DirectoryStream with something simple:

        File tmpFile = new File(fileNamePrefix + ".shx");
        if (tmpFile.exists())
            shxFile = tmpFile;
        tmpFile = new File(fileNamePrefix + ".dbf");
        if (tmpFile.exists())
            dbfFile = tmpFile;
        tmpFile = new File(fileNamePrefix + ".prj");
        if (tmpFile.exists())
            prjFile = tmpFile;

The SHPDriver works also on Android.

Not sure if this might be a change you would consider to make this work on Android?

Else is it possible to substitute the class used in the attach shp statement?


Thanks,
Andrea
Reply | Threaded
Open this post in threaded view
|

Re: Attach shapefile on Android

nicolas-f
Administrator
Hi,

Thanks for the feedback I've created an issue:

https://github.com/orbisgis/h2gis/issues/844

Nicolas Fortin