export to geojson featurecollection

97 views
Skip to first unread message

andrea antonello

unread,
Apr 23, 2017, 3:05:20 AM4/23/17
to spatiali...@googlegroups.com
Hello all,
I was wondering what would be the best way to export from spatialite to a geojson featurecollection.

Is there a better way than string concatenation like:

SELECT "{""type"":""FeatureCollection"",""features"":[" || group_concat(" {""type"":""Feature"",""geometry"":" || asGeoJSON(the_geom, 6, 0) || ",""properties"": {" || """attr1"":""" || attr1 || """" || "," || """attr2"":""" || attr2 || """" || "," || """attr3"":""" || attr3 || """" || "}}") || "]}" FROM table

Thanks,
Cheers,
Andrea

mj10777

unread,
Apr 23, 2017, 3:25:08 AM4/23/17
to SpatiaLite Users
You could simplify the query by using a single quote for the sql-string portion (avoiding double quotes inside the sql-string:
SELECT
 '{"type":"FeatureCollection","features":['||
  group_concat(' {"type":"Feature","geometry":'||
  asGeoJSON(geometry_polygon, 6, 0)||',"properties": {'||'"name":"'||name||'"'||','||'"notes":"'||notes||'"'||','||'"text":"'||text||'"'||'}}')||']}'
FROM admin_geometries;




Thanks,
Cheers,
Andrea

andrea antonello

unread,
Apr 23, 2017, 3:47:24 AM4/23/17
to spatiali...@googlegroups.com
Thanks Mark, this already helps a lot, since I am calling this from java and it gets really really addly readable :-)

Cheers,
Andrea

--
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-users+unsubscribe@googlegroups.com.
To post to this group, send email to spatialite-users@googlegroups.com.
Visit this group at https://groups.google.com/group/spatialite-users.
For more options, visit https://groups.google.com/d/optout.

mj10777

unread,
Apr 23, 2017, 3:48:59 AM4/23/17
to SpatiaLite Users


On Sunday, 23 April 2017 09:47:24 UTC+2, moovida wrote:
Thanks Mark, this already helps a lot, since I am calling this from java and it gets really really addly readable :-)
otherwise the combination of  'group_concat' and '||' is the best way to deal with this.

Cheers,
Andrea

On Sun, Apr 23, 2017 at 9:25 AM, 'mj10777' via SpatiaLite Users <spatiali...@googlegroups.com> wrote:


On Sunday, 23 April 2017 09:05:20 UTC+2, moovida wrote:
Hello all,
I was wondering what would be the best way to export from spatialite to a geojson featurecollection.

Is there a better way than string concatenation like:

SELECT "{""type"":""FeatureCollection"",""features"":[" || group_concat(" {""type"":""Feature"",""geometry"":" || asGeoJSON(the_geom, 6, 0) || ",""properties"": {" || """attr1"":""" || attr1 || """" || "," || """attr2"":""" || attr2 || """" || "," || """attr3"":""" || attr3 || """" || "}}") || "]}" FROM table

You could simplify the query by using a single quote for the sql-string portion (avoiding double quotes inside the sql-string:
SELECT
 '{"type":"FeatureCollection","features":['||
  group_concat(' {"type":"Feature","geometry":'||
  asGeoJSON(geometry_polygon, 6, 0)||',"properties": {'||'"name":"'||name||'"'||','||'"notes":"'||notes||'"'||','||'"text":"'||text||'"'||'}}')||']}'
FROM admin_geometries;




Thanks,
Cheers,
Andrea

--
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.
Reply all
Reply to author
Forward
0 new messages