Discussion:
[gdal-dev] Editing KML files using ogr_csharp.dll
Pouliot, Christopher (DNR)
2011-12-05 23:04:10 UTC
Permalink
Hello All,

I have a C# application that uses OGR_CSHARP.DLL to read/write KML files. I'm able to read from KML files fine. I'm able to create a new KML file and write to it fine. I am unable, however, to open a KML file to edit. I'd like to be able to append a new layer (folder) onto an existing KML file. I've tried both of the following code snippets:

//This returns NULL
OSGeo.OGR.Driver drv = Ogr.GetDriverByName("KML");
DataSource ds = drv.Open("c:\\temp\\mykml.kml", 1);


//This returns NULL
DataSource ds = Ogr.Open("c:\\temp\\mykml.kml", 1);


I'm able to use this code to edit File Geodatabases and Shapefiles but not KML.



Also, when creating a KML file from scratch is there a way to map the Name and Description fields to my existing fields so that the Name and Description appear in Google Earth?


Thanks,

Chris

Chris Pouliot
GIS Application Developer
Minnesota Department of Natural Resources
***@state.mn.us
(651) 259-5491

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/gdal-dev/attachments/20111205/826c961d/attachment.html
Kyle Shannon
2011-12-05 23:54:26 UTC
Permalink
Chris,

I don' know OGR very well, but I see a few issues. I also am not sure about the c# bindings, I believe they are pretty complete though.

'''OSGeo.OGR.Driver drv = Ogr.GetDriverByName("KML");
DataSource ds = drv.Open("c:\\temp\\mykml.kml", 1);'''

Open() opens existing files, you need to use driver->CreateDatasource() to create datasets. Open() opens files for editing. If mykml.kml exists, use Open().

see http://gdal.org/ogr/ogr_apitut.html for information on using OGR to read/write data

'''Also, when creating a KML file from scratch is there a way to map the Name and Description fields to my existing fields so that the Name and Description appear in Google Earth?'''

See http://gdal.org/ogr/drv_kml.html for this, it appears to be possible.

There is also the libkml driver: http://gdal.org/ogr/drv_libkml.html

kss

From: gdal-dev-***@lists.osgeo.org [mailto:gdal-dev-***@lists.osgeo.org] On Behalf Of Pouliot, Christopher (DNR)
Sent: Monday, December 05, 2011 7:51 AM
To: gdal-***@lists.osgeo.org
Subject: [gdal-dev] Editing KML files using ogr_csharp.dll

Hello All,

I have a C# application that uses OGR_CSHARP.DLL to read/write KML files. I'm able to read from KML files fine. I'm able to create a new KML file and write to it fine. I am unable, however, to open a KML file to edit. I'd like to be able to append a new layer (folder) onto an existing KML file. I've tried both of the following code snippets:

//This returns NULL
OSGeo.OGR.Driver drv = Ogr.GetDriverByName("KML");
DataSource ds = drv.Open("c:\\temp\\mykml.kml", 1);


//This returns NULL
DataSource ds = Ogr.Open("c:\\temp\\mykml.kml", 1);


I'm able to use this code to edit File Geodatabases and Shapefiles but not KML.



Also, when creating a KML file from scratch is there a way to map the Name and Description fields to my existing fields so that the Name and Description appear in Google Earth?


Thanks,

Chris

Chris Pouliot
GIS Application Developer
Minnesota Department of Natural Resources
***@state.mn.us<mailto:***@state.mn.us>
(651) 259-5491

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/gdal-dev/attachments/20111205/85e1e640/attachment.html
Pouliot, Christopher (DNR)
2011-12-06 00:05:07 UTC
Permalink
Thanks for the response Kyle.

I do use the CreateDataSource() to create a new KML. But am unable to open an existing KML for editing using the Open() code I specified below.

Chris

From: Kyle Shannon [mailto:***@gcs-research.com]
Sent: Monday, December 05, 2011 9:54 AM
To: Pouliot, Christopher (DNR); gdal-***@lists.osgeo.org
Subject: RE: Editing KML files using ogr_csharp.dll

Chris,

I don' know OGR very well, but I see a few issues. I also am not sure about the c# bindings, I believe they are pretty complete though.

'''OSGeo.OGR.Driver drv = Ogr.GetDriverByName("KML");
DataSource ds = drv.Open("c:\\temp\\mykml.kml", 1);'''

Open() opens existing files, you need to use driver->CreateDatasource() to create datasets. Open() opens files for editing. If mykml.kml exists, use Open().

see http://gdal.org/ogr/ogr_apitut.html for information on using OGR to read/write data

'''Also, when creating a KML file from scratch is there a way to map the Name and Description fields to my existing fields so that the Name and Description appear in Google Earth?'''

See http://gdal.org/ogr/drv_kml.html for this, it appears to be possible.

There is also the libkml driver: http://gdal.org/ogr/drv_libkml.html

kss

From: gdal-dev-***@lists.osgeo.org [mailto:gdal-dev-***@lists.osgeo.org] On Behalf Of Pouliot, Christopher (DNR)
Sent: Monday, December 05, 2011 7:51 AM
To: gdal-***@lists.osgeo.org
Subject: [gdal-dev] Editing KML files using ogr_csharp.dll

Hello All,

I have a C# application that uses OGR_CSHARP.DLL to read/write KML files. I'm able to read from KML files fine. I'm able to create a new KML file and write to it fine. I am unable, however, to open a KML file to edit. I'd like to be able to append a new layer (folder) onto an existing KML file. I've tried both of the following code snippets:

//This returns NULL
OSGeo.OGR.Driver drv = Ogr.GetDriverByName("KML");
DataSource ds = drv.Open("c:\\temp\\mykml.kml", 1);


//This returns NULL
DataSource ds = Ogr.Open("c:\\temp\\mykml.kml", 1);


I'm able to use this code to edit File Geodatabases and Shapefiles but not KML.



Also, when creating a KML file from scratch is there a way to map the Name and Description fields to my existing fields so that the Name and Description appear in Google Earth?


Thanks,

Chris

Chris Pouliot
GIS Application Developer
Minnesota Department of Natural Resources
***@state.mn.us<mailto:***@state.mn.us>
(651) 259-5491


This email message is for the sole use of the intended recipient(s) and may contain confidential and privileged information. Any unauthorized review, use, disclosure or distribution is prohibited. If you are not the intended recipient, please contact the sender by reply email and delete the original message.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/gdal-dev/attachments/20111205/198389e5/attachment-0001.html
Kyle Shannon
2011-12-06 00:09:39 UTC
Permalink
Can you report your gdal version and where you got it from? Is it from gisinternals.com/sdk, or did you build it yourself?

From: Pouliot, Christopher (DNR) [mailto:***@state.mn.us]
Sent: Monday, December 05, 2011 9:04 AM
To: Kyle Shannon; gdal-***@lists.osgeo.org
Subject: RE: Editing KML files using ogr_csharp.dll

Thanks for the response Kyle.

I do use the CreateDataSource() to create a new KML. But am unable to open an existing KML for editing using the Open() code I specified below.

Chris

From: Kyle Shannon [mailto:***@gcs-research.com]
Sent: Monday, December 05, 2011 9:54 AM
To: Pouliot, Christopher (DNR); gdal-***@lists.osgeo.org
Subject: RE: Editing KML files using ogr_csharp.dll

Chris,

I don' know OGR very well, but I see a few issues. I also am not sure about the c# bindings, I believe they are pretty complete though.

'''OSGeo.OGR.Driver drv = Ogr.GetDriverByName("KML");
DataSource ds = drv.Open("c:\\temp\\mykml.kml", 1);'''

Open() opens existing files, you need to use driver->CreateDatasource() to create datasets. Open() opens files for editing. If mykml.kml exists, use Open().

see http://gdal.org/ogr/ogr_apitut.html for information on using OGR to read/write data

'''Also, when creating a KML file from scratch is there a way to map the Name and Description fields to my existing fields so that the Name and Description appear in Google Earth?'''

See http://gdal.org/ogr/drv_kml.html for this, it appears to be possible.

There is also the libkml driver: http://gdal.org/ogr/drv_libkml.html

kss

From: gdal-dev-***@lists.osgeo.org [mailto:gdal-dev-***@lists.osgeo.org] On Behalf Of Pouliot, Christopher (DNR)
Sent: Monday, December 05, 2011 7:51 AM
To: gdal-***@lists.osgeo.org
Subject: [gdal-dev] Editing KML files using ogr_csharp.dll

Hello All,

I have a C# application that uses OGR_CSHARP.DLL to read/write KML files. I'm able to read from KML files fine. I'm able to create a new KML file and write to it fine. I am unable, however, to open a KML file to edit. I'd like to be able to append a new layer (folder) onto an existing KML file. I've tried both of the following code snippets:

//This returns NULL
OSGeo.OGR.Driver drv = Ogr.GetDriverByName("KML");
DataSource ds = drv.Open("c:\\temp\\mykml.kml", 1);


//This returns NULL
DataSource ds = Ogr.Open("c:\\temp\\mykml.kml", 1);


I'm able to use this code to edit File Geodatabases and Shapefiles but not KML.



Also, when creating a KML file from scratch is there a way to map the Name and Description fields to my existing fields so that the Name and Description appear in Google Earth?


Thanks,

Chris

Chris Pouliot
GIS Application Developer
Minnesota Department of Natural Resources
***@state.mn.us<mailto:***@state.mn.us>
(651) 259-5491


This email message is for the sole use of the intended recipient(s) and may contain confidential and privileged information. Any unauthorized review, use, disclosure or distribution is prohibited. If you are not the intended recipient, please contact the sender by reply email and delete the original message.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/gdal-dev/attachments/20111205/d390fb2d/attachment.html
Even Rouault
2011-12-06 00:38:12 UTC
Permalink
Post by Kyle Shannon
Can you report your gdal version and where you got it from? Is it from
gisinternals.com/sdk, or did you build it yourself?
The old KML driver only supports appending features to a file it has just
created. It can't work on an existing KML file that is re-opened afterwards,
since the driver only writes new lines at the end of the file (and you cannot
write after the ending </kml> marker ...)

The new LIBKML driver uses a in-memory DOM, so it is likely a better candidate
for updating KML files, but I haven't checked if it works indeed for that use
case.
Post by Kyle Shannon
Sent: Monday, December 05, 2011 9:04 AM
Subject: RE: Editing KML files using ogr_csharp.dll
Thanks for the response Kyle.
I do use the CreateDataSource() to create a new KML. But am unable to open
an existing KML for editing using the Open() code I specified below.
Chris
Sent: Monday, December 05, 2011 9:54 AM
Subject: RE: Editing KML files using ogr_csharp.dll
Chris,
I don' know OGR very well, but I see a few issues. I also am not sure about
the c# bindings, I believe they are pretty complete though.
'''OSGeo.OGR.Driver drv = Ogr.GetDriverByName("KML");
DataSource ds = drv.Open("c:\\temp\\mykml.kml", 1);'''
Open() opens existing files, you need to use driver->CreateDatasource() to
create datasets. Open() opens files for editing. If mykml.kml exists, use
Open().
see http://gdal.org/ogr/ogr_apitut.html for information on using OGR to read/write data
'''Also, when creating a KML file from scratch is there a way to map the Name
and Description fields to my existing fields so that the Name and Description
appear in Google Earth?'''
See http://gdal.org/ogr/drv_kml.html for this, it appears to be possible.
There is also the libkml driver: http://gdal.org/ogr/drv_libkml.html
kss
(DNR)
Sent: Monday, December 05, 2011 7:51 AM
Subject: [gdal-dev] Editing KML files using ogr_csharp.dll
Hello All,
I have a C# application that uses OGR_CSHARP.DLL to read/write KML files.
I'm able to read from KML files fine. I'm able to create a new KML file and
write to it fine. I am unable, however, to open a KML file to edit. I'd
like to be able to append a new layer (folder) onto an existing KML file.
//This returns NULL
OSGeo.OGR.Driver drv = Ogr.GetDriverByName("KML");
DataSource ds = drv.Open("c:\\temp\\mykml.kml", 1);
//This returns NULL
DataSource ds = Ogr.Open("c:\\temp\\mykml.kml", 1);
I'm able to use this code to edit File Geodatabases and Shapefiles but not KML.
Also, when creating a KML file from scratch is there a way to map the Name
and Description fields to my existing fields so that the Name and Description
appear in Google Earth?
Thanks,
Chris
Chris Pouliot
GIS Application Developer
Minnesota Department of Natural Resources
(651) 259-5491
This email message is for the sole use of the intended recipient(s) and may
contain confidential and privileged information. Any unauthorized review,
use, disclosure or distribution is prohibited. If you are not the intended
recipient, please contact the sender by reply email and delete the original
message.
Pouliot, Christopher (DNR)
2011-12-06 21:00:39 UTC
Permalink
Ok, thanks. I'll have to check that out.

-----Original Message-----
From: Even Rouault [mailto:***@mines-paris.org]
Sent: Monday, December 05, 2011 10:36 AM
To: Kyle Shannon
Cc: Pouliot, Christopher (DNR); gdal-***@lists.osgeo.org
Subject: Re: [gdal-dev] RE: Editing KML files using ogr_csharp.dll
Post by Kyle Shannon
Can you report your gdal version and where you got it from? Is it from
gisinternals.com/sdk, or did you build it yourself?
The old KML driver only supports appending features to a file it has just
created. It can't work on an existing KML file that is re-opened afterwards,
since the driver only writes new lines at the end of the file (and you cannot
write after the ending </kml> marker ...)

The new LIBKML driver uses a in-memory DOM, so it is likely a better candidate
for updating KML files, but I haven't checked if it works indeed for that use
case.
Post by Kyle Shannon
Sent: Monday, December 05, 2011 9:04 AM
Subject: RE: Editing KML files using ogr_csharp.dll
Thanks for the response Kyle.
I do use the CreateDataSource() to create a new KML. But am unable to open
an existing KML for editing using the Open() code I specified below.
Chris
Sent: Monday, December 05, 2011 9:54 AM
Subject: RE: Editing KML files using ogr_csharp.dll
Chris,
I don' know OGR very well, but I see a few issues. I also am not sure about
the c# bindings, I believe they are pretty complete though.
'''OSGeo.OGR.Driver drv = Ogr.GetDriverByName("KML");
DataSource ds = drv.Open("c:\\temp\\mykml.kml", 1);'''
Open() opens existing files, you need to use driver->CreateDatasource() to
create datasets. Open() opens files for editing. If mykml.kml exists, use
Open().
see http://gdal.org/ogr/ogr_apitut.html for information on using OGR to read/write data
'''Also, when creating a KML file from scratch is there a way to map the Name
and Description fields to my existing fields so that the Name and Description
appear in Google Earth?'''
See http://gdal.org/ogr/drv_kml.html for this, it appears to be possible.
There is also the libkml driver: http://gdal.org/ogr/drv_libkml.html
kss
(DNR)
Sent: Monday, December 05, 2011 7:51 AM
Subject: [gdal-dev] Editing KML files using ogr_csharp.dll
Hello All,
I have a C# application that uses OGR_CSHARP.DLL to read/write KML files.
I'm able to read from KML files fine. I'm able to create a new KML file and
write to it fine. I am unable, however, to open a KML file to edit. I'd
like to be able to append a new layer (folder) onto an existing KML file.
//This returns NULL
OSGeo.OGR.Driver drv = Ogr.GetDriverByName("KML");
DataSource ds = drv.Open("c:\\temp\\mykml.kml", 1);
//This returns NULL
DataSource ds = Ogr.Open("c:\\temp\\mykml.kml", 1);
I'm able to use this code to edit File Geodatabases and Shapefiles but not KML.
Also, when creating a KML file from scratch is there a way to map the Name
and Description fields to my existing fields so that the Name and Description
appear in Google Earth?
Thanks,
Chris
Chris Pouliot
GIS Application Developer
Minnesota Department of Natural Resources
(651) 259-5491
This email message is for the sole use of the intended recipient(s) and may
contain confidential and privileged information. Any unauthorized review,
use, disclosure or distribution is prohibited. If you are not the intended
recipient, please contact the sender by reply email and delete the original
message.
Pouliot, Christopher (DNR)
2011-12-06 00:38:24 UTC
Permalink
Yes, I'm using the development version (1.9) from gisinternals.com/sdk.

I need this version because I'm taking advantage of its ability to read/write File Geodatabases.


From: Kyle Shannon [mailto:***@gcs-research.com]
Sent: Monday, December 05, 2011 10:09 AM
To: Pouliot, Christopher (DNR); gdal-***@lists.osgeo.org
Subject: RE: Editing KML files using ogr_csharp.dll

Can you report your gdal version and where you got it from? Is it from gisinternals.com/sdk, or did you build it yourself?

From: Pouliot, Christopher (DNR) [mailto:***@state.mn.us]
Sent: Monday, December 05, 2011 9:04 AM
To: Kyle Shannon; gdal-***@lists.osgeo.org
Subject: RE: Editing KML files using ogr_csharp.dll

Thanks for the response Kyle.

I do use the CreateDataSource() to create a new KML. But am unable to open an existing KML for editing using the Open() code I specified below.

Chris

From: Kyle Shannon [mailto:***@gcs-research.com]
Sent: Monday, December 05, 2011 9:54 AM
To: Pouliot, Christopher (DNR); gdal-***@lists.osgeo.org
Subject: RE: Editing KML files using ogr_csharp.dll

Chris,

I don' know OGR very well, but I see a few issues. I also am not sure about the c# bindings, I believe they are pretty complete though.

'''OSGeo.OGR.Driver drv = Ogr.GetDriverByName("KML");
DataSource ds = drv.Open("c:\\temp\\mykml.kml", 1);'''

Open() opens existing files, you need to use driver->CreateDatasource() to create datasets. Open() opens files for editing. If mykml.kml exists, use Open().

see http://gdal.org/ogr/ogr_apitut.html for information on using OGR to read/write data

'''Also, when creating a KML file from scratch is there a way to map the Name and Description fields to my existing fields so that the Name and Description appear in Google Earth?'''

See http://gdal.org/ogr/drv_kml.html for this, it appears to be possible.

There is also the libkml driver: http://gdal.org/ogr/drv_libkml.html

kss

From: gdal-dev-***@lists.osgeo.org [mailto:gdal-dev-***@lists.osgeo.org] On Behalf Of Pouliot, Christopher (DNR)
Sent: Monday, December 05, 2011 7:51 AM
To: gdal-***@lists.osgeo.org
Subject: [gdal-dev] Editing KML files using ogr_csharp.dll

Hello All,

I have a C# application that uses OGR_CSHARP.DLL to read/write KML files. I'm able to read from KML files fine. I'm able to create a new KML file and write to it fine. I am unable, however, to open a KML file to edit. I'd like to be able to append a new layer (folder) onto an existing KML file. I've tried both of the following code snippets:

//This returns NULL
OSGeo.OGR.Driver drv = Ogr.GetDriverByName("KML");
DataSource ds = drv.Open("c:\\temp\\mykml.kml", 1);


//This returns NULL
DataSource ds = Ogr.Open("c:\\temp\\mykml.kml", 1);


I'm able to use this code to edit File Geodatabases and Shapefiles but not KML.



Also, when creating a KML file from scratch is there a way to map the Name and Description fields to my existing fields so that the Name and Description appear in Google Earth?


Thanks,

Chris

Chris Pouliot
GIS Application Developer
Minnesota Department of Natural Resources
***@state.mn.us<mailto:***@state.mn.us>
(651) 259-5491


This email message is for the sole use of the intended recipient(s) and may contain confidential and privileged information. Any unauthorized review, use, disclosure or distribution is prohibited. If you are not the intended recipient, please contact the sender by reply email and delete the original message.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/gdal-dev/attachments/20111205/fbd09946/attachment-0001.html
Brian Case
2011-12-05 23:55:15 UTC
Permalink
Chris,

Have you tried the libkml driver?

http://www.gdal.org/ogr/drv_libkml.html


Brian
Post by Pouliot, Christopher (DNR)
Hello All,
I have a C# application that uses OGR_CSHARP.DLL to read/write KML
files. I?m able to read from KML files fine. I?m able to create a
new KML file and write to it fine. I am unable, however, to open a
KML file to edit. I?d like to be able to append a new layer (folder)
onto an existing KML file. I?ve tried both of the following code
//This returns NULL
OSGeo.OGR.Driver drv = Ogr.GetDriverByName(?KML?);
DataSource ds = drv.Open(?c:\\temp\\mykml.kml?, 1);
//This returns NULL
DataSource ds = Ogr.Open(?c:\\temp\\mykml.kml?, 1);
I?m able to use this code to edit File Geodatabases and Shapefiles but
not KML.
Also, when creating a KML file from scratch is there a way to map the
Name and Description fields to my existing fields so that the Name and
Description appear in Google Earth?
Thanks,
Chris
Chris Pouliot
GIS Application Developer
Minnesota Department of Natural Resources
(651) 259-5491
_______________________________________________
gdal-dev mailing list
http://lists.osgeo.org/mailman/listinfo/gdal-dev
Loading...