Loading data from .shp files

279 views
Skip to first unread message

Ams Sol

unread,
Sep 30, 2014, 11:23:50 AM9/30/14
to spatiali...@googlegroups.com
Hi list,

I have been trying to make use of the tutorial at:
https://www.gaia-gis.it/fossil/libspatialite/wiki?name=spatialite-android-tutorial

Which creates a .sqllite database using shp files and tries to read coordinates etc with queries.

first off the tutorial is not clear at some point about cities1000.txt file.
and I could follow it. though even if i do, I would have to virtualize my shp files first into sqllite and then try to import them.

can anyone please help me with that issue. My main intention is to be able to load shp files and gather coordinate, information etc and display (or do whatever) in my application (for example build polygons).

appreciate your time.

Ams.

Ams Sol

unread,
Sep 30, 2014, 11:31:14 AM9/30/14
to spatiali...@googlegroups.com
and also write shp files into database ofcourse

Pac

unread,
Oct 1, 2014, 5:55:07 AM10/1/14
to spatiali...@googlegroups.com
Well, it's not clear for me what is your issue, but loading a SHP into a SpatiaLite DB is a different operation from virtualizing it in SpatiaLite: the former creates a table and fills it with data from that SHP, and after that the table is independent from the orignial SHP; the latter creates a table but doesn't load any data into it, meaning that SpatiaLite has to continue accessing the original SHP in order to get its data. Both operations have similar results, but through very different means.

In short: if you intend to load a SHP and forget about it, use "Load Shapefile" button not "Virtual Shapefile".

Ams Sol

unread,
Oct 2, 2014, 5:02:49 AM10/2/14
to spatiali...@googlegroups.com
thanks for the reply
maybe I havent made myself clear.
I dont want to use a GUI, my application needs an API to read/write shp files.
once I get my hands on for example a polygon imported from some .shp file then I can get their coordinate and do whatever I want
regards.

Noel Frankinet

unread,
Oct 2, 2014, 5:13:41 AM10/2/14
to spatiali...@googlegroups.com
If you just want to read/write shape files, shapelib maybe easier to use ?

Noël

--
You received this message because you are subscribed to the Google Groups "SpatiaLite Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to spatialite-use...@googlegroups.com.
To post to this group, send email to spatiali...@googlegroups.com.
Visit this group at http://groups.google.com/group/spatialite-users.
For more options, visit https://groups.google.com/d/optout.



--
Noël Frankinet
Strategis sprl
0478/90.92.54

Ams Sol

unread,
Oct 2, 2014, 6:03:47 AM10/2/14
to spatiali...@googlegroups.com
well its easier said than done just to use "shapelib".
I have been looking around for such libraries and most have java SPI problem and are not compatible with android. namely NoClassDefFoundEception all the time.
however I seem to have found one reader library but they can just read from shapefile.
I was hoping for something that can also write to a shapefile or create one, like java ESRI shapefile API which is robust but wont work for android.
I also didnt mention "some" java APIs which actually can create classes (no NoClassDefFoundEception) but, they cant load my shapefile through some program logic fail.
thanks

Noel Frankinet

unread,
Oct 2, 2014, 6:14:02 AM10/2/14
to spatiali...@googlegroups.com
Ah sorry, its a C lib of course, can you handle JNI or native calls I don't program on Android (yet).
Shapelib in itself is very simple:
open shapefile
read element
parse element (bbox, ccordinates)
if you want attributes, read the corresponding dbf record.
until all elements are readed
close

Brad Hards

unread,
Oct 2, 2014, 7:41:31 AM10/2/14
to spatiali...@googlegroups.com
On Thu, 2 Oct 2014 03:03:46 AM Ams Sol wrote:
> well its easier said than done just to use "shapelib".
> I have been looking around for such libraries and most have java SPI
> problem and are not compatible with android. namely NoClassDefFoundEception
> all the time.
Geotools? http://www.geotools.org/

Get the entry as WKT or WKB, and convert that if you need to write it to a
database, and vice versa.

Brad

Pac

unread,
Oct 2, 2014, 1:23:45 PM10/2/14
to spatiali...@googlegroups.com
Well, you're lucky: Sandro announced RELEASE: SpatiaLite 4.2.1 RC0, and as said in new SQL functions introduced since version 4.2.1 (dot macros replacement) you have now ImportShapefile(), described as ImportSHP() in SpatiaLite 4.2.1 SQL functions reference list.

Before SpatiaLite 4.2.1 you only had the dot macro .loadshp in spatialite CLI tool.

JaakL

unread,
Oct 3, 2014, 5:53:28 AM10/3/14
to spatiali...@googlegroups.com


On Thursday, October 2, 2014 2:41:31 PM UTC+3, Brad Hards wrote:
On Thu, 2 Oct 2014 03:03:46 AM Ams Sol wrote:
> well its easier said than done just to use "shapelib".
> I have been looking around for such libraries and most have java SPI
> problem and are not compatible with android. namely NoClassDefFoundEception
> all the time.
Geotools? http://www.geotools.org/

Geotools does not run on Android, it uses some tricky Java features not available there. I dont know any other Java tool available to read Shapefile.

I would use OGR/GDAL, which runs on Android and reads and writes Shapefiles.

My project (for Android): https://github.com/nutiteq/hellomap3d/wiki/Ogr-layer

Jaak
 

Jukka Rahkonen

unread,
Oct 3, 2014, 3:34:32 PM10/3/14
to spatiali...@googlegroups.com
JaakL wrote 2014-10-03 12:53:
> On Thursday, October 2, 2014 2:41:31 PM UTC+3, Brad Hards wrote:
>
>> On Thu, 2 Oct 2014 03:03:46 AM Ams Sol wrote:
>>> well its easier said than done just to use "shapelib".
>>> I have been looking around for such libraries and most have java
>> SPI
>>> problem and are not compatible with android. namely
>> NoClassDefFoundEception
>>> all the time.
>> Geotools? http://www.geotools.org/ [1]
>
> Geotools does not run on Android, it uses some tricky Java features
> not available there. I dont know any other Java tool available to read
> Shapefile.
>
> I would use OGR/GDAL, which runs on Android and reads and writes
> Shapefiles.
>
> My project (for Android):
> https://github.com/nutiteq/hellomap3d/wiki/Ogr-layer
>
> Jaak


Hi,

OpenJUMP is java and lightweight and build on top of Java Topology Suite
(JTS). The shapefile reader/writer code is in
http://sourceforge.net/p/jump-pilot/code/HEAD/tree/core/trunk/src/com/vividsolutions/jump/io/
As far as I know nobody has tried to run OpenJUMP on Android.

Deegree is also java and can read shapefiles but it is, like geotools, a
big library and probably not easy to use on Android.

-Jukka Rahkonen-

JaakL

unread,
Oct 4, 2014, 2:21:15 AM10/4/14
to spatiali...@googlegroups.com
On Friday, October 3, 2014 10:34:32 PM UTC+3, Jukka Rahkonen wrote:
JaakL wrote 2014-10-03 12:53:
> On Thursday, October 2, 2014 2:41:31 PM UTC+3, Brad Hards wrote:
>
>> On Thu, 2 Oct 2014 03:03:46 AM Ams Sol wrote:
>>> well its easier said than done just to use "shapelib".
>>> I have been looking around for such libraries and most have java
>> SPI
>>> problem and are not compatible with android. namely
>> NoClassDefFoundEception
>>> all the time.
>> Geotools? http://www.geotools.org/ [1]
>
> Geotools does not run on Android, it uses some tricky Java features
> not available there. I dont know any other Java tool available to read
> Shapefile.
>
> I would use OGR/GDAL, which runs on Android and reads and writes
> Shapefiles.
>
> My project (for Android):
> https://github.com/nutiteq/hellomap3d/wiki/Ogr-layer
>
> Jaak


OpenJUMP is java and lightweight and build on top of Java Topology Suite
(JTS). The shapefile reader/writer code is in
http://sourceforge.net/p/jump-pilot/code/HEAD/tree/core/trunk/src/com/vividsolutions/jump/io/
As far as I know nobody has tried to run OpenJUMP on Android.

Well, their ShapefileReader.java over there is not very encouraging:

import org.geotools.dbffile.DbfFile;
import org.geotools.shapefile.Shapefile;
import org.geotools.shapefile.ShapefileException;

 
Deegree is also java and can read shapefiles but it is, like geotools, a
big library and probably not easy to use on Android.

Right, Deegree itself is huge server system, but their Shp reader[1] does not  seem to have impossible external dependencies. So with a few days refactoring - replace their internal (geometry) objects with JTS or something own, it might be even usable as stand-alone thing. Performance-wise native lib like OGR would be much faster, but pure Java has its advantages also.

[1] https://github.com/deegree/deegree3/tree/7ff0509642244308172dc41ef9b4ea5fa794bc2e/deegree-datastores/deegree-featurestores/deegree-featurestore-shape/src/main/java/org/deegree/feature/persistence/shape

Jaak

Jukka Rahkonen

unread,
Oct 4, 2014, 4:36:45 AM10/4/14
to spatiali...@googlegroups.com
JaakL wrote 2014-10-04 09:21:
> On Friday, October 3, 2014 10:34:32 PM UTC+3, Jukka Rahkonen wrote:
>
>> JaakL wrote 2014-10-03 12:53:
>>> On Thursday, October 2, 2014 2:41:31 PM UTC+3, Brad Hards wrote:
>>>
>>>> On Thu, 2 Oct 2014 03:03:46 AM Ams Sol wrote:
>>>>> well its easier said than done just to use "shapelib".
>>>>> I have been looking around for such libraries and most have java
>>
>>>> SPI
>>>>> problem and are not compatible with android. namely
>>>> NoClassDefFoundEception
>>>>> all the time.
>>>> Geotools? http://www.geotools.org/ [1] [1]
>>>
>>> Geotools does not run on Android, it uses some tricky Java
>> features
>>> not available there. I dont know any other Java tool available to
>> read
>>> Shapefile.
>>>
>>> I would use OGR/GDAL, which runs on Android and reads and writes
>>> Shapefiles.
>>>
>>> My project (for Android):
>>> https://github.com/nutiteq/hellomap3d/wiki/Ogr-layer [2]
>>>
>>> Jaak
>>
>> OpenJUMP is java and lightweight and build on top of Java Topology
>> Suite
>> (JTS). The shapefile reader/writer code is in
>>
> http://sourceforge.net/p/jump-pilot/code/HEAD/tree/core/trunk/src/com/vividsolutions/jump/io/
>> [3]
>> As far as I know nobody has tried to run OpenJUMP on Android.
>
> Well, their ShapefileReader.java over there is not very encouraging:
>
> import org.geotools.dbffile.DbfFile;
>
> import org.geotools.shapefile.Shapefile;
>
> import org.geotools.shapefile.ShapefileException;

Yes, I noticed that later. However, there reads also that a modified
geotools code is used. Perhaps worth having a look also to directory
http://sourceforge.net/p/jump-pilot/code/HEAD/tree/core/trunk/src/org/geotools/shapefile/


>> Deegree is also java and can read shapefiles but it is, like
>> geotools, a
>> big library and probably not easy to use on Android.
>
> Right, Deegree itself is huge server system, but their Shp reader[1]
> does not seem to have impossible external dependencies. So with a few
> days refactoring - replace their internal (geometry) objects with JTS
> or something own, it might be even usable as stand-alone thing.
> Performance-wise native lib like OGR would be much faster, but pure
> Java has its advantages also.
>
> [1]
> https://github.com/deegree/deegree3/tree/7ff0509642244308172dc41ef9b4ea5fa794bc2e/deegree-datastores/deegree-featurestores/deegree-featurestore-shape/src/main/java/org/deegree/feature/persistence/shape
>
> Jaak

-Jukka-
Reply all
Reply to author
Forward
0 new messages