[gdal-dev] How to read GML/GeoRSS directly from XML string?

Yingqi Tang anakintang at gmail.com
Thu Jul 5 11:44:58 PDT 2012


Hi Chaitanya,

GeoJSON does seem to be an exception, although the ogr driver can directly
read the GeoJSON string, the generic virtual memory file doesn't seem to
work:

    inputDataStr = "{geojson_string}";
    gdal.FileFromMemBuffer('/vsimem/temp', inputDataStr);
    inputDriver.Open('/vsimem/temp', 0);

Is that expected?

Thanks.

On Thu, Jul 5, 2012 at 10:19 AM, Yingqi Tang <anakintang at gmail.com> wrote:

> Hi Chaitanya,
>
> This works great, thanks a lot for the advice. Here is basic code pattern:
>
>     inputDataStr = "<input_geojson_or_gml_str>";
>     gdal.FileFromMemBuffer('/vsimem/temp', inputDataStr);
>     inputDriver.Open('/vsimem/temp', 0);
>
> Thanks,
> Yingqi
>
> On Tue, Jul 3, 2012 at 8:18 PM, Chaitanya kumar CH <chaitanya.ch at gmail.com
> > wrote:
>
>> Yingqi,
>>
>> Though the GeoJSON driver allows for reading the data directly, it is
>> more like an exception. For consistent behavior between formats, you need
>> to read the data from a data source like a file or url.
>>
>> You can create a temporary in-memory file of your data using the method
>>
>> gdal.FileFromMemBuffer()
>>
>> Example at http://www.gdal.org/ogr/drv_georss.html
>>
>> There are also a few methods to import/export just the geometries. You
>> can import GML and WKT [1] and export to GML, KML and JSON[2].
>>
>> [1]: http://www.gdal.org/ogr/classOGRGeometryFactory.html
>> [2]: http://www.gdal.org/ogr/classOGRGeometry.html
>>
>> On Wed, Jul 4, 2012 at 3:34 AM, Yingqi Tang <anakintang at gmail.com> wrote:
>>
>>> Hi,
>>>
>>> I am using OGR/GDAL to read GML/GeoRSS/GeoJSON from either local file or
>>> url, the sample code is like below
>>> ...
>>> inputDriver = ogr.GetDriverByName(inputDriverType)
>>> inputDataSource = inputDriver.Open(inputDataPath, 0);
>>> ...
>>>
>>> It seems that I can pass in the GeoJSON string directly like:
>>>
>>> inputDataSource = inputDriver.Open("
>>>
>>> {'type':'FeatureCollection','features':[{'type':'Feature','id':'OpenLayers.Feature.Vector_3449','properties':{},'geometry':{'type':'Polygon','coordinates':[[[-109.3449,
>>> 63.6328125
>>> ],[-112.5,35.5078125],[-85.078125,34.8046875],[-68.90625,39.7265625],[-68.203125,
>>> 67.1484375],[-109.6875,63.6328125
>>> ]]]},'crs':{'type':'OGC','properties':{'urn':'urn:ogc:def:crs:OGC:1.3:CRS84'}}},{'type':'Feature','id':'OpenLayers.Feature.Vector_07050618','properties':{},'geometry':{'type':'Polygon','coordinates':[[[-40.78125,
>>> 65.0390625
>>> ],[-40.078125,34.8046875],[-12.3449,25.6640625],[21.09375,17.2265625],[22.5,58.0078125],[-40.78125,
>>> 65.0390625]]]},'crs':{'type':'OGC','properties':{'urn':'urn:ogc:def:crs:OGC:1.3:CRS84'}}}]}",
>>> 0);
>>>
>>> But it doesn't seem to work with GML or GeoRSS, did I miss anything? So
>>> basically how can I read GML/GeoRSS directly from an XML string?
>>>
>>> Thanks
>>>
>>> _______________________________________________
>>> gdal-dev mailing list
>>> gdal-dev at lists.osgeo.org
>>> http://lists.osgeo.org/mailman/listinfo/gdal-dev
>>>
>>
>>
>>
>> --
>> Best regards,
>> Chaitanya kumar CH.
>>
>> +91-9494447584
>> 17.2416N 80.1426E
>>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/gdal-dev/attachments/20120705/8d913727/attachment-0001.html>


More information about the gdal-dev mailing list