The command line tool 'spatialite' has a command to dump
the content of a spatialite database as SQL statements:
spatialite> .dump
But the geometry columns are dumped in the internal spatialite format.
For example:
INSERT INTO foo VALUES(..., X'0001FF...40FE');
I'd prefer the .dump command to dump the geometry columns as text like this:
INSERT INTO foo VALUES(..., GeomFromText('POINT(123.45 543.21)'));
Is this possible?
It would make it possible export a spatialite database and import
it into another database such as MySQL.
Thanks
Dominique
Have you tried running the AsText() function on your geom column? Try
that and see if it helps.
Adam
2010/8/6 Dominique Pellé <dominiq...@gmail.com>:
> --
> You received this message because you are subscribed to the Google Groups "SpatiaLite Users" group.
> To post to this group, send email to spatiali...@googlegroups.com.
> To unsubscribe from this group, send email to spatialite-use...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/spatialite-users?hl=en.
>
>
I know about AsText(...) but it's a quite inconvenient to use for
dumping an entire database which may contain several tables
with several geometry columns.
The best I found so far is this:
spatialite> .mode insert
spatialite> select *, AsText(geometry) from myTable;
INSERT INTO table VALUES(..., 'POINT(123.45 543.21)');
...
But then I have to write a script to transform the output of
the command to:
- substitute "INSERT INTO table" with "INSERT INTO myTable"
- substitute things like 'POINT(123.45, 543.21)' with
GeomFromText('POINT(123.45, 543.21)')
- do this it for all tables, figuring out what are the geometry columns
to be able to put them in the select statement.
There might (or should) be a simpler way.
Regards
Dominique
Hi Sandro
Thanks for taking the time to respond in details. I'm new to
spatialite and I learned a I few things from your response.
For now, I think can still try to use my patch privately (possibly with
WKB instead of WKT to avoid losing precision). But in the longer
term, I look forward using your new "data exchange tool".
I indeed overlooked the vanishing SRID value since spatialite
stores SRID in the blob. I could in theory retrieve it from the blob
(4 bytes at offset #2) as described at:
http://www.gaia-gis.it/spatialite/spatialite-manual-2.3.1.html#t3.3
But since all my geometries use the same SRID, an option to specify
the SRID can also be a pragmatic short term solution until your "data
exchange tool" becomes available.
Regards
Dominique