[OpenLayers-Dev] Saving drawn polygons

John Powell john.powell at emapsite.com
Wed Feb 3 05:15:57 EST 2010


In response to the question about saving polygons, it is also worth 
looking at Format.WKT as this produces polygons in OGC compliant format 
which can then be inserted into a spatially enabled database such as 
Postgres or MySQL.

Somthing like


layer.events.register('featureadded', this, function(obj){
    var wktwriter=new OpenLayers.Format.WKT();
    var wkt=wktwriter.write(obj.feature);
}

wkt will now look something like POLYGON(( x1 y1, x2 y2, .....x1, y1))

and you can insert this into a geometry column of a db using the 
geomfromtext function.


dev-request at openlayers.org wrote:
> Send Dev mailing list submissions to
>         dev at openlayers.org
>
> To subscribe or unsubscribe via the World Wide Web, visit
>         http://openlayers.org/mailman/listinfo/dev
> or, via email, send a message with subject or body 'help' to
>         dev-request at openlayers.org
>
> You can reach the person managing the list at
>         dev-owner at openlayers.org
>
> When replying, please edit your Subject line so it is more specific
> than "Re: Contents of Dev digest..."
>
>
> Today's Topics:
>
>    1. Geotiff from database (Ashwin Dhakal)
>    2. preserving scale on base layer switching (Tim Schaub)
>    3. Re: Save drawn polygon (Tim Schaub)
>    4. Re: preserving scale on base layer switching (Andreas Hocevar)
>    5. Re: onImageLoadError not triggered on Google Chrome for some
>       missing Tilecache tiles... (TonnyCZ)
>    6. reproject using vector and protocol (WFS) is not  working
>       (Steven M. Ottens)
>    7. Re: reproject using vector and protocol (WFS) is  not working
>       (Bart van den Eijnden)
>
>
> ----------------------------------------------------------------------
>
> Message: 1
> Date: Tue, 2 Feb 2010 13:05:32 -0800 (PST)
> From: Ashwin Dhakal <ashwindhakal at yahoo.com>
> Subject: [OpenLayers-Dev] Geotiff from database
> To: Dev at openlayers.org
> Message-ID: <239605.56632.qm at web52303.mail.re2.yahoo.com>
> Content-Type: text/plain; charset=us-ascii
>
> Hi all
> I am working a project which I have to finish very soon but I have a problem with open layers. How can I import Geotiff image from postgis database.  any one has worked on it please send me that source code or send me how can i solve this. For me it is very important to solve the problem.
>
> please help
> reagrds
> ashwin
>
>
>
>
>
> ------------------------------
>
> Message: 2
> Date: Tue, 02 Feb 2010 18:22:08 -0700
> From: Tim Schaub <tschaub at opengeo.org>
> Subject: [OpenLayers-Dev] preserving scale on base layer switching
> To: OpenLayers Dev <dev at openlayers.org>
> Message-ID: <4B68CFC0.3000400 at opengeo.org>
> Content-Type: text/plain; charset=ISO-8859-1; format=flowed
>
> Hey-
>
> Currently, when a new base layer is set, we determine the new resolution
> based on the previous map extent.  An alternative would be to determine
> the new resolution based on the previous scale.  Preserving center and
> scale makes better sense to me.  I'm curious what others think.
>
> The resolution based on extent method breaks down when extents are not
> well defined.  E.g. with an extent that wraps the date line.  To see
> this break-down in action, follow these steps:
>
> 1) open http://openlayers.org/dev/examples/google.html
> 2) click to zoom all the way out (you'll see multiple worlds)
> 3) open the switcher and change base layers
>
> You should see the scale change.
>
> Apply the patch for http://trac.openlayers.org/ticket/2457 and you
> should see better behavior.
>
> Thanks for any feedback.
> Tim
>
> --
> Tim Schaub
> OpenGeo - http://opengeo.org
> Expert service straight from the developers.
>
>
> ------------------------------
>
> Message: 3
> Date: Tue, 02 Feb 2010 18:29:21 -0700
> From: Tim Schaub <tschaub at opengeo.org>
> Subject: Re: [OpenLayers-Dev] Save drawn polygon
> To: dev at openlayers.org
> Message-ID: <4B68D171.2020209 at opengeo.org>
> Content-Type: text/plain; charset=ISO-8859-1; format=flowed
>
> Alex G. wrote:
>   
>> Thanks for the link!
>>
>> I am not sure how I can get the info I get on hover after the user finishes
>> drawing a polygon. Another thought would be to "get" all the drawn shapes
>> from the vector layer. After going through the layer functions I wasn't able
>> to find any such function. Does one exist?
>>
>>     
>
> Assuming you have a vector layer, you can create a listener to respond
> when features are added to the layer (by a draw control for example):
>
>      layer.events.on({
>          featuresadded: function(event) {
>              console.log("newly added features: " + event.features);
>          }
>      });
>
> At any time, you can get all the features on the layer:
>
>      // all features on the layer
>      console.log(layer.features);
>
> And if you want to serialize the features, you'll use one of the
> available formats.  E.g.
>
>      var format = new OpenLayers.Format.GeoJSON();
>      var str = format.write(layer.features);
>
> More information on vector layer events:
> http://dev.openlayers.org/apidocs/files/OpenLayers/Layer/Vector-js.html#OpenLayers.Layer.Vector.EVENT_TYPES
>
> Tim
>
>   
>> Thanks in advance for any help!
>>
>> On Mon, Feb 1, 2010 at 5:14 PM, Bart van den Eijnden <bartvde at osgis.nl>wrote:
>>
>>     
>>> See:
>>>
>>>
>>> http://dev.openlayers.org/releases/OpenLayers-2.8/examples/vector-formats.html
>>>
>>> Best regards,
>>> Bart
>>>
>>> On Feb 1, 2010, at 4:10 PM, Alex G. wrote:
>>>
>>> Hello,
>>>
>>> I am using the drawing example (
>>> http://openlayers.org/dev/examples/editingtoolbar.html) on OpenLayers to
>>> allow users to draw lines and polygons on my map.
>>>
>>> I was wondering how may I "save" the polygons that they have drawn. Is
>>> there some way to get the coordinates they have clicked and then save them
>>> to some database or external file? Is there some built-in function to return
>>> the coordinates clicked or something similar?
>>>
>>> Do I have to "record" the clicks that the user makes and save them? If yes,
>>> how could I go about doing that?
>>>
>>> Thanks in advance,
>>>
>>> Alex
>>> _______________________________________________
>>> Dev mailing list
>>> Dev at openlayers.org
>>> http://openlayers.org/mailman/listinfo/dev
>>>
>>>
>>>
>>>       
>> ------------------------------------------------------------------------
>>
>> _______________________________________________
>> Dev mailing list
>> Dev at openlayers.org
>> http://openlayers.org/mailman/listinfo/dev
>>     
>
>
> --
> Tim Schaub
> OpenGeo - http://opengeo.org
> Expert service straight from the developers.
>
>
> ------------------------------
>
> Message: 4
> Date: Wed, 03 Feb 2010 06:58:16 +0100
> From: Andreas Hocevar <ahocevar at opengeo.org>
> Subject: Re: [OpenLayers-Dev] preserving scale on base layer switching
> To: Tim Schaub <tschaub at opengeo.org>
> Cc: OpenLayers Dev <dev at openlayers.org>
> Message-ID: <4B691078.6080904 at opengeo.org>
> Content-Type: text/plain; charset=ISO-8859-1; format=flowed
>
> Tim Schaub wrote:
>   
>> Currently, when a new base layer is set, we determine the new resolution
>> based on the previous map extent.  An alternative would be to determine
>> the new resolution based on the previous scale.  Preserving center and
>> scale makes better sense to me.  I'm curious what others think.
>>
>>     
>
> I totally agree. This should also improve behavior when switching
> between base layers with different projections/units.
>
> -Andreas.
>
>   
>> The resolution based on extent method breaks down when extents are not
>> well defined.  E.g. with an extent that wraps the date line.  To see
>> this break-down in action, follow these steps:
>>
>> 1) open http://openlayers.org/dev/examples/google.html
>> 2) click to zoom all the way out (you'll see multiple worlds)
>> 3) open the switcher and change base layers
>>
>> You should see the scale change.
>>
>> Apply the patch for http://trac.openlayers.org/ticket/2457 and you
>> should see better behavior.
>>
>> Thanks for any feedback.
>> Tim
>>
>>
>>     
>
>
> --
> Andreas Hocevar
> OpenGeo - http://opengeo.org/
> Expert service straight from the developers.
>
>
>
> ------------------------------
>
> Message: 5
> Date: Wed, 3 Feb 2010 00:43:25 -0800 (PST)
> From: TonnyCZ <tonny at tonny.cz>
> Subject: Re: [OpenLayers-Dev] onImageLoadError not triggered on Google
>         Chrome for some missing Tilecache tiles...
> To: dev at openlayers.org
> Message-ID: <1265186605657-4506090.post at n2.nabble.com>
> Content-Type: text/plain; charset=us-ascii
>
>
> Hi,
> the same problem is with LoadingPanel
> (http://trac.openlayers.org/wiki/Addins/LoadingPanel). The loading image in
> Google Chrome sometimes appear, sometime not.
> No idea what it causes... :-(
> T.
> --
> View this message in context: http://n2.nabble.com/onImageLoadError-not-triggered-on-Google-Chrome-for-some-missing-Tilecache-tiles-tp4486629p4506090.html
> Sent from the OpenLayers Dev mailing list archive at Nabble.com.
>
>
> ------------------------------
>
> Message: 6
> Date: Wed, 03 Feb 2010 10:26:00 +0100
> From: "Steven M. Ottens" <steven at minst.net>
> Subject: [OpenLayers-Dev] reproject using vector and protocol (WFS) is
>         not     working
> To: dev at openlayers.org
> Message-ID: <4B694128.9070704 at minst.net>
> Content-Type: text/plain; charset="iso-8859-1"
>
> Hi all,
>
> I'm trying to access a WFS in epsg:30800, while the background layer and
> all other WFS's are in epsg:4258. I've configured all WFS's using Vector
> and protocol.WFS. I've set the projection in the layer definition, and
> the WFS request does contain the correct epsg code, but the coordinates
> are still in 4258. I checked the Vector class and didn't see anything
> related to projection, am I correct in assuming that Vector.js together
> with the WFS protocol doesn't support reprojecting features? If so
> should I create a ticket, since WFS.js does support it
> (http://trac.openlayers.org/ticket/1406)
>
> regards,
> Steven
>
> Configuration of the working WFS:
> var wfs_nl_cp = new OpenLayers.Layer.Vector(
>      "The Netherlands: CP",
>      {
>          strategies: [new OpenLayers.Strategy.BBOX({resFactor: 1})],
>          visibility: true,
>          projection: new OpenLayers.Projection("EPSG:4258"),
>          protocol: new OpenLayers.Protocol.WFS({
>              version: "1.1.0",
>              srsName: "EPSG:4258",
>              extractAttributes:true,
>              url:
> "http://esdin.geodan.nl/fgi/Kadaster/deegree-wfs/services",
>              featurePrefix: "CP",
>              featureType: "CadastralParcel",
>              featureNS:
> "urn:x-inspire:specification:gmlas:CadastralParcels:3.0",
>              geometryName: "geometry",
>              maxFeatures: "100",
>              sortBy: "label", //not supported
>              schema:
> "http://esdin.fgi.fi/esdin/Kadaster/deegree-wfs/services?request=DescribeFeatureType&version=1.1.0&service=WFS&typeName=CP:CadastralParcel&namespace=xmlns(xmlns:CP=urn:x-inspire:specification:gmlas:CadastralParcels:3.0)"
>          })
>      }
>      );
> and the not working WFS:
>      var wfs_se_gn = new OpenLayers.Layer.Vector(
>      "Sweden: GN",
>      {
>          strategies: [new OpenLayers.Strategy.BBOX({resFactor: 1})],
>          visibility: false,
>          styleMap: pointStyles,
>          projection: new OpenLayers.Projection("EPSG:30800"),
>          protocol: new OpenLayers.Protocol.WFS({
>              version: "1.1.0",
>              srsName: "EPSG:30800",
>              extractAttributes:true,
>              url: "http://esdin.geodan.nl/fgi/NLSS/geoserver_esdin/wfs",
>              featurePrefix: "esdin",
>              featureType: "geographicalNames",
>              featureNS: "http://www.metainfo.se/esdin",
>              geometryName: "SHAPE",
>              schema:
> "http://esdin.geodan.nl/fgi/NLSS/geoserver_esdin/wfs?&request=DescribeFeatureType&version=1.1.0&typeName=esdin:geographicalNames"
>          })
>      }
>      );
>
> The post request generated with the second layer is:
> |<wfs:GetFeature xmlns:wfs="http://www.opengis.net/wfs" service="WFS"
> version="1.1.0" xsi:schemaLocation||="http://www.opengis.net/wfs
> http://schemas.opengis.net/wfs/1.1.0/wfs.xsd"
> xmlns:xsi="http://www.w3.org||/2001/XMLSchema-instance">
> <wfs:Query typeName="esdin:geographicalNames" srsName="EPSG:30800"
> xmlns:esdin||="http://www.metainfo.se/esdin">
> <ogc:Filter xmlns:ogc="http://www.opengis.net/ogc">
> <ogc:BBOX>
> <ogc:PropertyName||>SHAPE</ogc:PropertyName>
> <gml:Envelope xmlns:gml="http://www.opengis.net/gml" srsName="EPSG:30800">
> <gml||:lowerCorner>-45.25 16.72265625</gml:lowerCorner>
> <gml:upperCorner>67.25 85.27734375</gml:upperCorner||>
> </gml:Envelope>
> </ogc:BBOX>
> </ogc:Filter>
> </wfs:Query>
> </wfs:GetFeature>|
>
> -------------- next part --------------
> An HTML attachment was scrubbed...
> URL: http://openlayers.org/pipermail/dev/attachments/20100203/5eae706a/attachment-0001.htm
>
> ------------------------------
>
> Message: 7
> Date: Wed, 3 Feb 2010 10:35:37 +0100
> From: Bart van den Eijnden <bartvde at osgis.nl>
> Subject: Re: [OpenLayers-Dev] reproject using vector and protocol
>         (WFS) is        not working
> To: "Steven M. Ottens" <steven at minst.net>
> Cc: dev at openlayers.org
> Message-ID: <6583FEEA-A9CA-4D14-BED2-39BDF01E3F48 at osgis.nl>
> Content-Type: text/plain; charset="us-ascii"
>
> Hi Steven,
>
> the format reading the features is responsible for reprojection, not the layer. Have you tried supplying internalProjection and externalProjection through the formatOptions property of the protocol?
>
> Is it not easier to have your WFS reproject the features for you?
>
> Best regards,
> Bart
>
> On Feb 3, 2010, at 10:26 AM, Steven M. Ottens wrote:
>
>   
>> Hi all,
>>
>> I'm trying to access a WFS in epsg:30800, while the background layer and all other WFS's are in epsg:4258. I've configured all WFS's using Vector and protocol.WFS. I've set the projection in the layer definition, and the WFS request does contain the correct epsg code, but the coordinates are still in 4258. I checked the Vector class and didn't see anything related to projection, am I correct in assuming that Vector.js together with the WFS protocol doesn't support reprojecting features? If so should I create a ticket, since WFS.js does support it (http://trac.openlayers.org/ticket/1406)
>>
>> regards,
>> Steven
>>
>> Configuration of the working WFS:
>> var wfs_nl_cp = new OpenLayers.Layer.Vector(
>>     "The Netherlands: CP",
>>     {
>>         strategies: [new OpenLayers.Strategy.BBOX({resFactor: 1})],
>>         visibility: true,
>>         projection: new OpenLayers.Projection("EPSG:4258"),
>>         protocol: new OpenLayers.Protocol.WFS({
>>             version: "1.1.0",
>>             srsName: "EPSG:4258",
>>             extractAttributes:true,
>>             url: "http://esdin.geodan.nl/fgi/Kadaster/deegree-wfs/services",
>>             featurePrefix: "CP",
>>             featureType: "CadastralParcel",
>>             featureNS: "urn:x-inspire:specification:gmlas:CadastralParcels:3.0",
>>             geometryName: "geometry",
>>             maxFeatures: "100",
>>             sortBy: "label", //not supported
>>             schema: "http://esdin.fgi.fi/esdin/Kadaster/deegree-wfs/services?request=DescribeFeatureType&version=1.1.0&service=WFS&typeName=CP:CadastralParcel&namespace=xmlns(xmlns:CP=urn:x-inspire:specification:gmlas:CadastralParcels:3.0)"
>>         })
>>     }
>>     );
>> and the not working WFS:
>>     var wfs_se_gn = new OpenLayers.Layer.Vector(
>>     "Sweden: GN",
>>     {
>>         strategies: [new OpenLayers.Strategy.BBOX({resFactor: 1})],
>>         visibility: false,
>>         styleMap: pointStyles,
>>         projection: new OpenLayers.Projection("EPSG:30800"),
>>         protocol: new OpenLayers.Protocol.WFS({
>>             version: "1.1.0",
>>             srsName: "EPSG:30800",
>>             extractAttributes:true,
>>             url: "http://esdin.geodan.nl/fgi/NLSS/geoserver_esdin/wfs",
>>             featurePrefix: "esdin",
>>             featureType: "geographicalNames",
>>             featureNS: "http://www.metainfo.se/esdin",
>>             geometryName: "SHAPE",
>>             schema: "http://esdin.geodan.nl/fgi/NLSS/geoserver_esdin/wfs?&request=DescribeFeatureType&version=1.1.0&typeName=esdin:geographicalNames"
>>         })
>>     }
>>     );
>>
>> The post request generated with the second layer is:
>> <wfs:GetFeature xmlns:wfs="http://www.opengis.net/wfs" service="WFS" version="1.1.0" xsi:schemaLocation="http://www.opengis.net/wfs http://schemas.opengis.net/wfs/1.1.0/wfs.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
>> <wfs:Query typeName="esdin:geographicalNames" srsName="EPSG:30800" xmlns:esdin="http://www.metainfo.se/esdin">
>> <ogc:Filter xmlns:ogc="http://www.opengis.net/ogc">
>> <ogc:BBOX>
>> <ogc:PropertyName>SHAPE</ogc:PropertyName>
>> <gml:Envelope xmlns:gml="http://www.opengis.net/gml" srsName="EPSG:30800">
>> <gml:lowerCorner>-45.25 16.72265625</gml:lowerCorner>
>> <gml:upperCorner>67.25 85.27734375</gml:upperCorner>
>> </gml:Envelope>
>> </ogc:BBOX>
>> </ogc:Filter>
>> </wfs:Query>
>> </wfs:GetFeature>
>>
>> _______________________________________________
>> Dev mailing list
>> Dev at openlayers.org
>> http://openlayers.org/mailman/listinfo/dev
>>     
>
> -------------- next part --------------
> An HTML attachment was scrubbed...
> URL: http://openlayers.org/pipermail/dev/attachments/20100203/03feb1ed/attachment.htm
>
> ------------------------------
>
> _______________________________________________
> Dev mailing list
> Dev at openlayers.org
> http://openlayers.org/mailman/listinfo/dev
>
>
> End of Dev Digest, Vol 41, Issue 3
> **********************************
>   

-- 

*John Powell*

email: john.powell at emapsite.com
tel:       +44 (0)118 973 6883
mob:    +34 628 605909

www.emapsite.com <http://www.emapsite.com/>


*emapsite*
MASDAR House, 1 Reading Road, Eversley, Hants RG27 0RP

Please only print this email if it is essential

Please note that all correspondence and contracts are subject to 
emapsite's terms and conditions, copy available on request

Confidentiality Note
The information in this message may be confidential or privileged and is 
for the use of the named recipient only. If you are not the intended 
recipient you may not copy or deliver this message to anyone. If you 
receive this message in error please notify us immediately by telephone, 
fax or email.

It is the recipient's responsibility to take any action necessary to 
prevent computer viruses being transmitted. Accordingly, emapsite 
disclaims all responsibility which arises directly or indirectly from 
such transmission of computer viruses

Registered Office: MASDAR House, 1 Reading Road, Eversley, Hants RG27 
0RP  Company Reg. No: 3931726

 

 




More information about the Dev mailing list