[OpenLayers-Users] Saving features (points, lines and polygons) using GeoJSON or WKT

Noli Sicad nsicad at gmail.com
Thu Aug 18 07:41:24 EDT 2011


Hi,

I would like to save features (i.e.point, lines and polygons) into
Spatialite database using GeoJSON or WKT. These features are created
by the users. The ideas is to use Openlayers as mobile GIS in iOS and
Android devices.

Yes, I can use sqlite3 / spatialite with Openlayers. Right now, I can
query my spatialite database to render points, lines and polygons into
the OL map as showed below.

~~~~~~
<textarea style="color: green; background-color: black"
  name="SQLinput" id="SQLinput" >SELECT postcode, AsText(Geometry)
FROM AusPostCode Where suburb = 'MELBOURNE'</textarea>
				
<div class="button color black" value='Execute Query'
ontouchend="handleRequest('queryGeometry')" ><span>Execute
Query</span></div>
~~~~~~~

I would like to INSERT points into Point_Table, INSERT lines into
Line_Table as well as INSERT polygons into Polygon_Table  in local
Spatialite database.

 Now, how can I select / get the individual vector features created by
the user (i.e points, lines and polygons) and convert it into GeoJSON
or WKT  and save into tables.

I understand that we can get all the vector features as mentioned in
this post. However, I don't have idea how get the individual feature
and save it.

~~~~~~~~~~
// http://osgeo-org.1803224.n2.nabble.com/saving-a-vector-file-permanently-td5947700.html

var format = new OpenLayers.Format.GeoJSON();

// given that 'layer' is a vector layer attached to the map with some features:
var jsonstring = format.write( layer.features );

// given that 'txtarea' is an HTML textarea element somewhere in your
page to display the geojson:
txtarea.value = jsonstring;
~~~~~~~~~~~

In Spatialite, I can do these:

For example, Point_Table

~~~~~~~~~~
CREATE TABLE test_geom_Point (
  id INTEGER NOT NULL
    PRIMARY KEY AUTOINCREMENT,
  name TEXT NOT NULL,
  date DATE NOT NULL,
  measured_value DOUBLE NOT NULL);


SELECT AddGeometryColumn('test_geom_Point', 'the_geom',
  4326, 'POINT', 'XY');


WKT:

INSERT INTO test_geom_Point
    (id, name, date, measured_value, the_geom)
  VALUES (NULL, 'first point', 1.23456,
    GeomFromText('POINT(1.01 2.02)', 4326));

GeoJSON:

INSERT INTO test_geom_Point
    (id, name, date, measured_value, the_geom)
  VALUES (NULL, 'first point', 1.23456,
GeomFromGeoJSON('{"type":"Point","crs":{"type":"name",
"properties":{"name":"EPSG:4326"}},
"bbox":[-1.23455679,9.87654321,-1.23455679,9.87654321],
"coordinates":[-1.23455679,9.87654321]}'))

~~~~~~~

Again, my question is how to get the individual features (points,
lines, and polygons) and place them into variables?

~~~~~

var point1 = ?

var format = new OpenLayers.Format.GeoJSON();
var line2  = format.write( ? ?);
..

INSERT INTO test_geom_Point
    (id, name, date, measured_value, the_geom)
  VALUES (NULL, 'first point', 1.23456,
    GeomFromText( point1, 4326));

INSERT INTO test_geom_Lines
    (id, name, date, measured_value, the_geom)
  VALUES (NULL, 'first point', 1.23456,
    GeomFromGeoJSON( line1, 4326));

~~~~

Thanks in advance.

Noli


More information about the Users mailing list