[OSGeo Africa] Batch conversion from shp to kml
Gerhard Brits
BritsJG at eskom.co.za
Mon Aug 15 06:25:15 PDT 2016
HI Mnqweno
Below is a snippet from a python I use to import into Oracle spatial Using gdal. Rather than using ogr2ogr Python module that can be a bit difficult get to work. Call the required windows function from python using subprocess. In the snippet you will need to change the OCI part to KML.
See below:
result = subprocess.Popen('ogr2ogr -f OCI OCI:username/password at 111.11.11.111:1521/gisqa {0} -lco DIM=2 -lco SRID=4148 -lco INDEX=NO -lco DIMINFO_X="-180,180,1" -lco DIMINFO_Y="-90,90,1" -lco GEOMETRY_NAME="GEOM"'.format(out),stdout= subprocess.PIPE, stderr= subprocess.PIPE, shell = True)
Please check the org2ogr documentation for kml creation options.
Regards
-----Original Message-----
From: Africa [mailto:africa-bounces at lists.osgeo.org] On Behalf Of africa-request at lists.osgeo.org
Sent: 15 August 2016 03:12 PM
To: africa at lists.osgeo.org
Subject: Africa Digest, Vol 114, Issue 26
Send Africa mailing list submissions to
africa at lists.osgeo.org<mailto:africa at lists.osgeo.org>
To subscribe or unsubscribe via the World Wide Web, visit
http://lists.osgeo.org/mailman/listinfo/africa
or, via email, send a message with subject or body 'help' to
africa-request at lists.osgeo.org<mailto:africa-request at lists.osgeo.org>
You can reach the person managing the list at
africa-owner at lists.osgeo.org<mailto:africa-owner at lists.osgeo.org>
When replying, please edit your Subject line so it is more specific than "Re: Contents of Africa digest..."
Today's Topics:
1. Re: Batch conversion from shp to kml (Zibusiso Ncube)
2. Re: Batch conversion from shp to kml (Nditsheni Matsheketsheke)
----------------------------------------------------------------------
Message: 1
Date: Mon, 15 Aug 2016 15:11:51 +0200
From: Zibusiso Ncube <ncubezedm at gmail.com<mailto:ncubezedm at gmail.com>>
To: Africa local chapter discussions <africa at lists.osgeo.org<mailto:africa at lists.osgeo.org>>
Subject: Re: [OSGeo Africa] Batch conversion from shp to kml
Message-ID:
<CAHiii_YX2huxUhN1a2CsGUcOjQ3WBqf9_obQim8y2pheRCzR+w at mail.gmail.com<mailto:CAHiii_YX2huxUhN1a2CsGUcOjQ3WBqf9_obQim8y2pheRCzR+w at mail.gmail.com>>
Content-Type: text/plain; charset="utf-8"
Hi Mnqweno
i realised i had some errors in the little idea i sent earlier...maybe try and modify this one i wrote quickly ..it might have some errors so just play around with it till it works and if i have time i will write someting for you tomorrow.
'''
Created on 15 Aug 2016
@author: NcubeZ
'''
"""
download and install your system specific GDAL binaries from https://trac.osgeo.org/gdal/wiki/DownloadingGdalBinaries
or ask through another email and gurus like Tim can help you
"""
from convertor import ogr2ogr
import os
from osgeo import ogr
def filePathNamesList(directoryPath, extension):
""" List of all files of a specific extension within a specific directory
path - directory in which the files are contained e.g C:\\dir\\subDir\\subSubDir\\subSubSubDir
extension - file extension e.g. .txt
"""
fileList=[]
for f in os.listdir(directoryPath):
if f.endswith(extension):
fileList.append(directoryPath +"\\" +f)
return fileList
def convertshptokml(outputPath,inputPath):
""" OGR2OGR """
ogr2ogr.main(['-f', 'KML', outputPath,inputPath])
#################
#in your main
#################
def main():
#pathList=None
'''
you could add some method to iterate through sub directories and get all path names
and returns a fullist of all shpfiles within your work directory instead of my smallanyana
methodinyana i used as an example
but for now it is just the input of directory where your shapefile are immediately contained, it will not search further in sub directories '''
pathList=filePathNamesList(r"C:\Users\Zibusiso\Desktop\TestShapefiles",
extension)
extension=".shp"
#print(pathList)
for shpPath in pathList:
#remove .shp and add .kml to path name
kmlPath=path[:-4]+".kml"
convertshptokml(kmlPath, shpPath)
outputPath=None
if __name__ == "__main__":
main()
Regards
Zibusiso M Ncube
On Mon, Aug 15, 2016 at 1:04 PM, Mnqweno Mnyengeza <mnqwenom at statssa.gov.za<mailto:mnqwenom at statssa.gov.za>>
wrote:
> Dear All
>
> I need to convert approximately thirteen million points from shp2kml
> using QGIS. I have already split the points into their respective
> provinces, districts and the lowest level of demarcation which is an
> enumeration area (EA) here at Statistics South Africa. The output file
> of the split is the sub-folder named the EA reference number and
> containing the points and polygon of that particular EA. I now need to
> batch process this conversion using QGIS batch file processor if any
> is available or any other free open source tool that can easily serve the purpose.
>
> Please assist
>
>
> Kind regards
>
> Mnqweno Mnyengeza (Mr)
>
> Professional GIS Practitioner
> Geography
> 082 9048267 (Mobile)
> Statistics South Africa
> "..*.people are very quick to notice the change in your attitude
> towards them but always ignore their unacceptable behavior that led to
> your change* ....."
>
>
>
>
> _______________________________________________
> Africa mailing list
> Africa at lists.osgeo.org<mailto:Africa at lists.osgeo.org>
> You can UNSUBSCRIBE at http://lists.osgeo.org/mailman/listinfo/africa
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/africa/attachments/20160815/b521fb76/attachment-0001.html>
------------------------------
Message: 2
Date: Mon, 15 Aug 2016 14:33:12 +0200
From: Nditsheni Matsheketsheke <ndicheni at gmail.com<mailto:ndicheni at gmail.com>>
To: Africa local chapter discussions <africa at lists.osgeo.org<mailto:africa at lists.osgeo.org>>
Subject: Re: [OSGeo Africa] Batch conversion from shp to kml
Message-ID:
<CACDPLN7tPYifVRtiEesULNytDyuXGzLxa8A__z3Cnp9ibTL=Ug at mail.gmail.com<mailto:CACDPLN7tPYifVRtiEesULNytDyuXGzLxa8A__z3Cnp9ibTL=Ug at mail.gmail.com>>
Content-Type: text/plain; charset="utf-8"
in qgis
go to selection and choose how you want to select them
[image: Inline image 2]
after selecting all points, go to layer, right click, save as, a new dialog box will pop up named save vector layer as
[image: Inline image 4]
change format from ESRI Shapefile to KML then still in the same dialig box change encoding to save only selected features
[image: Inline image 5]
then browse and save it in workspace
ok.
There you go
On Mon, Aug 15, 2016 at 2:09 PM, Zoltan Szecsei <zoltans at geograph.co.za<mailto:zoltans at geograph.co.za>>
wrote:
> Hi,
>
> shp2kml is a product, you do realise?
>
> Presumably you mean you have a bunch of SHP files and want them in KML
> format but don't want to use shp2kml?
>
>
> Try ogr2ogr - using the command-line approach you should have zero
> difficulties doing it "in a snap"
>
>
> Regards,
>
> Zoltan
>
> On 2016-08-15 13:04, Mnqweno Mnyengeza wrote:
>
> Dear All
>
> I need to convert approximately thirteen million points *from shp2kml
> using QGIS*. I have already split the points into their respective
> provinces, districts and the lowest level of demarcation which is an
> enumeration area (EA) here at Statistics South Africa. The output file
> of the split is the sub-folder named the EA reference number and
> containing the points and polygon of that particular EA. I now need to
> batch process this conversion using QGIS batch file processor if any
> is available or any other free open source tool that can easily serve the purpose.
>
> Please assist
>
>
> Kind regards
>
> Mnqweno Mnyengeza (Mr)
>
> Professional GIS Practitioner
> Geography
> 082 9048267 (Mobile)
> Statistics South Africa
>
>
>
> _______________________________________________
> Africa mailing list
> Africa at lists.osgeo.org<mailto:Africa at lists.osgeo.org>
> You can UNSUBSCRIBE at http://lists.osgeo.org/mailman/listinfo/africa
>
--
*Names :Matsheketsheke Nnditsheni Jonathan*
*Position : Research Executive: Mapping AdministratorCompany :
Continental Outdoor MediaEmail :ndicheni at gmail.com
<ndicheni at gmail.com<mailto:ndicheni at gmail.com>> and jonathanm at continental.com<mailto:jonathanm at continental.com>
<jonathan at nrmconsulting.co.za<mailto:jonathan at nrmconsulting.co.za>>*
* <http://www.nrmconsulting.co.za/>*
*Cell :0720324899 *
*Tel :011 514 1612 *
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/africa/attachments/20160815/520a1c5c/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image.png
Type: image/png
Size: 67556 bytes
Desc: not available
URL: <http://lists.osgeo.org/pipermail/africa/attachments/20160815/520a1c5c/attachment.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image.png
Type: image/png
Size: 10989 bytes
Desc: not available
URL: <http://lists.osgeo.org/pipermail/africa/attachments/20160815/520a1c5c/attachment-0001.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image.png
Type: image/png
Size: 65734 bytes
Desc: not available
URL: <http://lists.osgeo.org/pipermail/africa/attachments/20160815/520a1c5c/attachment-0002.png>
------------------------------
Subject: Digest Footer
_______________________________________________
Africa mailing list
Africa at lists.osgeo.org<mailto:Africa at lists.osgeo.org>
http://lists.osgeo.org/mailman/listinfo/africa
------------------------------
End of Africa Digest, Vol 114, Issue 26
***************************************
I'm part of the 49Million initiative...
www.eskom.co.za/idm
NB: This Email and its contents are subject to the Eskom Holdings SOC Limited EMAIL LEGAL NOTICE which can be viewed at http://www.eskom.co.za/Pages/Email_Legal_Spam_Disclaimer.aspx
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/africa/attachments/20160815/a19e4ea8/attachment-0001.html>
More information about the Africa
mailing list