Empty shapefile created with Python and GDALWriting a shapefile using OGR, from Shapely Geometry - No feature...

Change the color of a single dot in `ddot` symbol

Non-trope happy ending?

How to draw a matrix with arrows in limited space

Did the UK lift the requirement for registering SIM cards?

Shouldn’t conservatives embrace universal basic income?

How do you make your own symbol when Detexify fails?

Has any country ever had 2 former presidents in jail simultaneously?

What does "Scientists rise up against statistical significance" mean? (Comment in Nature)

Creating two special characters

Does an advisor owe his/her student anything? Will an advisor keep a PhD student only out of pity?

Review your own paper in Mathematics

Microchip documentation does not label CAN buss pins on micro controller pinout diagram

The Digit Triangles

Multiplicative persistence

Strong empirical falsification of quantum mechanics based on vacuum energy density?

Does the reader need to like the PoV character?

Why does Carol not get rid of the Kree symbol on her suit when she changes its colours?

Why do ¬, ∀ and ∃ have the same precedence?

Stack Interview Code methods made from class Node and Smart Pointers

How to explain what's wrong with this application of the chain rule?

Why is it that I can sometimes guess the next note?

Why does AES have exactly 10 rounds for a 128-bit key, 12 for 192 bits and 14 for a 256-bit key size?

Do we have to expect a queue for the shuttle from Watford Junction to Harry Potter Studio?

Why is the "ls" command showing permissions of files in a FAT32 partition?



Empty shapefile created with Python and GDAL


Writing a shapefile using OGR, from Shapely Geometry - No feature added ErrorDLL load error with Gdal polygonize in QGIS 1.8 (windows 7)Capture GDAL projection and create matching output (OGR or GDAL) shapefiles?Conflict between ArcPy and GDAL/OGR?Image processing using Python, GDAL and Scikit-ImageConnecting points located in opposite side of international date meridian using Python GDAL/OGR?Create ShapeFile from CSV Using OGR and PythonCalculate total area of polygons in shapefile using GDAL?GDAL/OGR (Python) GetGeomType() method returns integer, what is the matching geom type?Set or change the geometry type of an empty point shapefile using Python with GDAL/OGRHow to create a grid of 10degx10deg polygons for a shapefile using GDAL













1















I need to create a point shapefile using the coordinates specified in the variable I called "my_points_dataset".



'my_points_dataset' variable has this structure:



1615311.055743243079633 4820229.073873873800039 0,1615321.055743243079633 4820229.073873873800039 0,1615331.055743243079633 4820229.073873873800039 0,1615341.055743243079633 4820229.073873873800039 0,1615351.055743243079633 4820229.073873873800039 0, etc`


The class of this variable is 'osgeo.ogr.Geometry'



Each point in 'my_points_dataset' is defined as x, y and z coordinates (z could be negligeable because is always 0).
x, y and z data are separated by a space, each point is separated by comma.



I wrote this Python code, but at the end the result is an empty shapefile.
Do yo know why?



import ogr, gdal
shpDriver = ogr.GetDriverByName('ESRI Shapefile')
if os.path.exists('/path/mypoints.shp'):
shpDriver.DeleteDataSource('/path/points_shapefile.shp')
outDataSource = shpDriver.CreateDataSource('/path/points_shapefile.shp')
outLayer = outDataSource.CreateLayer('/path/points_shapefile.shp', geom_type=ogr.wkbMultiPoint)
featureDefn = outLayer.GetLayerDefn()
outFeature = ogr.Feature(featureDefn)
outFeature.SetGeometry(my_points_dataset)
outLayer.CreateFeature(outFeature)
outFeature = None









share|improve this question
















bumped to the homepage by Community 4 mins ago


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
















  • Compare your code with the cookbook example pcjericks.github.io/py-gdalogr-cookbook/….

    – user30184
    Feb 14 at 10:17











  • This is what I did, I took my code from "Convert polygon to points" pcjericks.github.io/py-gdalogr-cookbook/vector_layers.html.

    – ilFonta
    Feb 14 at 10:22











  • It seem that you have skipped many steps before doing outFeature.SetGeometry(my_points_dataset). Have you tried to use the code of the tutorial exactly?

    – user30184
    Feb 14 at 10:35













  • Yes I did. I copied/pasted the example from pcjerks in spyder and I used a general shapefile with only one polygon as test. The firsta part of the example works and the point net is created and saved in my_points-dataset. The conversion to shapefile doesn't work.

    – ilFonta
    Feb 14 at 10:49













  • It seems that you have modified the example by adding z coordinate, is that right? I guess that wkbMultiPoint is not correct geometry type for your x, y, z data. Drop z coordinates and try again. I am not sure what type matches your data but perhaps it is wkbMultiPoint25D gdal.org /ogr__core_8h.html#a800236a0d460ef66e687b7b65610f12a.

    – user30184
    Feb 14 at 11:21
















1















I need to create a point shapefile using the coordinates specified in the variable I called "my_points_dataset".



'my_points_dataset' variable has this structure:



1615311.055743243079633 4820229.073873873800039 0,1615321.055743243079633 4820229.073873873800039 0,1615331.055743243079633 4820229.073873873800039 0,1615341.055743243079633 4820229.073873873800039 0,1615351.055743243079633 4820229.073873873800039 0, etc`


The class of this variable is 'osgeo.ogr.Geometry'



Each point in 'my_points_dataset' is defined as x, y and z coordinates (z could be negligeable because is always 0).
x, y and z data are separated by a space, each point is separated by comma.



I wrote this Python code, but at the end the result is an empty shapefile.
Do yo know why?



import ogr, gdal
shpDriver = ogr.GetDriverByName('ESRI Shapefile')
if os.path.exists('/path/mypoints.shp'):
shpDriver.DeleteDataSource('/path/points_shapefile.shp')
outDataSource = shpDriver.CreateDataSource('/path/points_shapefile.shp')
outLayer = outDataSource.CreateLayer('/path/points_shapefile.shp', geom_type=ogr.wkbMultiPoint)
featureDefn = outLayer.GetLayerDefn()
outFeature = ogr.Feature(featureDefn)
outFeature.SetGeometry(my_points_dataset)
outLayer.CreateFeature(outFeature)
outFeature = None









share|improve this question
















bumped to the homepage by Community 4 mins ago


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
















  • Compare your code with the cookbook example pcjericks.github.io/py-gdalogr-cookbook/….

    – user30184
    Feb 14 at 10:17











  • This is what I did, I took my code from "Convert polygon to points" pcjericks.github.io/py-gdalogr-cookbook/vector_layers.html.

    – ilFonta
    Feb 14 at 10:22











  • It seem that you have skipped many steps before doing outFeature.SetGeometry(my_points_dataset). Have you tried to use the code of the tutorial exactly?

    – user30184
    Feb 14 at 10:35













  • Yes I did. I copied/pasted the example from pcjerks in spyder and I used a general shapefile with only one polygon as test. The firsta part of the example works and the point net is created and saved in my_points-dataset. The conversion to shapefile doesn't work.

    – ilFonta
    Feb 14 at 10:49













  • It seems that you have modified the example by adding z coordinate, is that right? I guess that wkbMultiPoint is not correct geometry type for your x, y, z data. Drop z coordinates and try again. I am not sure what type matches your data but perhaps it is wkbMultiPoint25D gdal.org /ogr__core_8h.html#a800236a0d460ef66e687b7b65610f12a.

    – user30184
    Feb 14 at 11:21














1












1








1


1






I need to create a point shapefile using the coordinates specified in the variable I called "my_points_dataset".



'my_points_dataset' variable has this structure:



1615311.055743243079633 4820229.073873873800039 0,1615321.055743243079633 4820229.073873873800039 0,1615331.055743243079633 4820229.073873873800039 0,1615341.055743243079633 4820229.073873873800039 0,1615351.055743243079633 4820229.073873873800039 0, etc`


The class of this variable is 'osgeo.ogr.Geometry'



Each point in 'my_points_dataset' is defined as x, y and z coordinates (z could be negligeable because is always 0).
x, y and z data are separated by a space, each point is separated by comma.



I wrote this Python code, but at the end the result is an empty shapefile.
Do yo know why?



import ogr, gdal
shpDriver = ogr.GetDriverByName('ESRI Shapefile')
if os.path.exists('/path/mypoints.shp'):
shpDriver.DeleteDataSource('/path/points_shapefile.shp')
outDataSource = shpDriver.CreateDataSource('/path/points_shapefile.shp')
outLayer = outDataSource.CreateLayer('/path/points_shapefile.shp', geom_type=ogr.wkbMultiPoint)
featureDefn = outLayer.GetLayerDefn()
outFeature = ogr.Feature(featureDefn)
outFeature.SetGeometry(my_points_dataset)
outLayer.CreateFeature(outFeature)
outFeature = None









share|improve this question
















I need to create a point shapefile using the coordinates specified in the variable I called "my_points_dataset".



'my_points_dataset' variable has this structure:



1615311.055743243079633 4820229.073873873800039 0,1615321.055743243079633 4820229.073873873800039 0,1615331.055743243079633 4820229.073873873800039 0,1615341.055743243079633 4820229.073873873800039 0,1615351.055743243079633 4820229.073873873800039 0, etc`


The class of this variable is 'osgeo.ogr.Geometry'



Each point in 'my_points_dataset' is defined as x, y and z coordinates (z could be negligeable because is always 0).
x, y and z data are separated by a space, each point is separated by comma.



I wrote this Python code, but at the end the result is an empty shapefile.
Do yo know why?



import ogr, gdal
shpDriver = ogr.GetDriverByName('ESRI Shapefile')
if os.path.exists('/path/mypoints.shp'):
shpDriver.DeleteDataSource('/path/points_shapefile.shp')
outDataSource = shpDriver.CreateDataSource('/path/points_shapefile.shp')
outLayer = outDataSource.CreateLayer('/path/points_shapefile.shp', geom_type=ogr.wkbMultiPoint)
featureDefn = outLayer.GetLayerDefn()
outFeature = ogr.Feature(featureDefn)
outFeature.SetGeometry(my_points_dataset)
outLayer.CreateFeature(outFeature)
outFeature = None






python gdal






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Feb 14 at 10:20









Vince

14.7k32749




14.7k32749










asked Feb 14 at 9:58









ilFontailFonta

488311




488311





bumped to the homepage by Community 4 mins ago


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.







bumped to the homepage by Community 4 mins ago


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.















  • Compare your code with the cookbook example pcjericks.github.io/py-gdalogr-cookbook/….

    – user30184
    Feb 14 at 10:17











  • This is what I did, I took my code from "Convert polygon to points" pcjericks.github.io/py-gdalogr-cookbook/vector_layers.html.

    – ilFonta
    Feb 14 at 10:22











  • It seem that you have skipped many steps before doing outFeature.SetGeometry(my_points_dataset). Have you tried to use the code of the tutorial exactly?

    – user30184
    Feb 14 at 10:35













  • Yes I did. I copied/pasted the example from pcjerks in spyder and I used a general shapefile with only one polygon as test. The firsta part of the example works and the point net is created and saved in my_points-dataset. The conversion to shapefile doesn't work.

    – ilFonta
    Feb 14 at 10:49













  • It seems that you have modified the example by adding z coordinate, is that right? I guess that wkbMultiPoint is not correct geometry type for your x, y, z data. Drop z coordinates and try again. I am not sure what type matches your data but perhaps it is wkbMultiPoint25D gdal.org /ogr__core_8h.html#a800236a0d460ef66e687b7b65610f12a.

    – user30184
    Feb 14 at 11:21



















  • Compare your code with the cookbook example pcjericks.github.io/py-gdalogr-cookbook/….

    – user30184
    Feb 14 at 10:17











  • This is what I did, I took my code from "Convert polygon to points" pcjericks.github.io/py-gdalogr-cookbook/vector_layers.html.

    – ilFonta
    Feb 14 at 10:22











  • It seem that you have skipped many steps before doing outFeature.SetGeometry(my_points_dataset). Have you tried to use the code of the tutorial exactly?

    – user30184
    Feb 14 at 10:35













  • Yes I did. I copied/pasted the example from pcjerks in spyder and I used a general shapefile with only one polygon as test. The firsta part of the example works and the point net is created and saved in my_points-dataset. The conversion to shapefile doesn't work.

    – ilFonta
    Feb 14 at 10:49













  • It seems that you have modified the example by adding z coordinate, is that right? I guess that wkbMultiPoint is not correct geometry type for your x, y, z data. Drop z coordinates and try again. I am not sure what type matches your data but perhaps it is wkbMultiPoint25D gdal.org /ogr__core_8h.html#a800236a0d460ef66e687b7b65610f12a.

    – user30184
    Feb 14 at 11:21

















Compare your code with the cookbook example pcjericks.github.io/py-gdalogr-cookbook/….

– user30184
Feb 14 at 10:17





Compare your code with the cookbook example pcjericks.github.io/py-gdalogr-cookbook/….

– user30184
Feb 14 at 10:17













This is what I did, I took my code from "Convert polygon to points" pcjericks.github.io/py-gdalogr-cookbook/vector_layers.html.

– ilFonta
Feb 14 at 10:22





This is what I did, I took my code from "Convert polygon to points" pcjericks.github.io/py-gdalogr-cookbook/vector_layers.html.

– ilFonta
Feb 14 at 10:22













It seem that you have skipped many steps before doing outFeature.SetGeometry(my_points_dataset). Have you tried to use the code of the tutorial exactly?

– user30184
Feb 14 at 10:35







It seem that you have skipped many steps before doing outFeature.SetGeometry(my_points_dataset). Have you tried to use the code of the tutorial exactly?

– user30184
Feb 14 at 10:35















Yes I did. I copied/pasted the example from pcjerks in spyder and I used a general shapefile with only one polygon as test. The firsta part of the example works and the point net is created and saved in my_points-dataset. The conversion to shapefile doesn't work.

– ilFonta
Feb 14 at 10:49







Yes I did. I copied/pasted the example from pcjerks in spyder and I used a general shapefile with only one polygon as test. The firsta part of the example works and the point net is created and saved in my_points-dataset. The conversion to shapefile doesn't work.

– ilFonta
Feb 14 at 10:49















It seems that you have modified the example by adding z coordinate, is that right? I guess that wkbMultiPoint is not correct geometry type for your x, y, z data. Drop z coordinates and try again. I am not sure what type matches your data but perhaps it is wkbMultiPoint25D gdal.org /ogr__core_8h.html#a800236a0d460ef66e687b7b65610f12a.

– user30184
Feb 14 at 11:21





It seems that you have modified the example by adding z coordinate, is that right? I guess that wkbMultiPoint is not correct geometry type for your x, y, z data. Drop z coordinates and try again. I am not sure what type matches your data but perhaps it is wkbMultiPoint25D gdal.org /ogr__core_8h.html#a800236a0d460ef66e687b7b65610f12a.

– user30184
Feb 14 at 11:21










1 Answer
1






active

oldest

votes


















0














I found the solution in gene's answer in
Writing a shapefile using OGR, from Shapely Geometry - No feature added Error



 # Write point coordinates to Shapefile
shpDriver = ogr.GetDriverByName('ESRI Shapefile')

# Set the crs
latlong = osr.SpatialReference()
latlong.ImportFromEPSG( 3003 )

if os.path.exists('/path/mypoints.shp'):
shpDriver.DeleteDataSource('/path/mypoints.shp')

outDataSource = shpDriver.CreateDataSource('/path/mypoints.shp')
outLayer = outDataSource.CreateLayer('', srs=latlong, geom_type=ogr.wkbMultiPoint)
outLayer.CreateField(ogr.FieldDefn('id', ogr.OFTInteger))
outDefn = outLayer.GetLayerDefn()
outFeature = ogr.Feature(outDefn)
outFeature.SetField('id', 1)
outFeature.SetGeometry(my_points_dataset)
outLayer.CreateFeature(outFeature)

# Remove temporary files
outDataSource.Destroy()





share|improve this answer























    Your Answer








    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "79"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: false,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: null,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fgis.stackexchange.com%2fquestions%2f312186%2fempty-shapefile-created-with-python-and-gdal%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    I found the solution in gene's answer in
    Writing a shapefile using OGR, from Shapely Geometry - No feature added Error



     # Write point coordinates to Shapefile
    shpDriver = ogr.GetDriverByName('ESRI Shapefile')

    # Set the crs
    latlong = osr.SpatialReference()
    latlong.ImportFromEPSG( 3003 )

    if os.path.exists('/path/mypoints.shp'):
    shpDriver.DeleteDataSource('/path/mypoints.shp')

    outDataSource = shpDriver.CreateDataSource('/path/mypoints.shp')
    outLayer = outDataSource.CreateLayer('', srs=latlong, geom_type=ogr.wkbMultiPoint)
    outLayer.CreateField(ogr.FieldDefn('id', ogr.OFTInteger))
    outDefn = outLayer.GetLayerDefn()
    outFeature = ogr.Feature(outDefn)
    outFeature.SetField('id', 1)
    outFeature.SetGeometry(my_points_dataset)
    outLayer.CreateFeature(outFeature)

    # Remove temporary files
    outDataSource.Destroy()





    share|improve this answer




























      0














      I found the solution in gene's answer in
      Writing a shapefile using OGR, from Shapely Geometry - No feature added Error



       # Write point coordinates to Shapefile
      shpDriver = ogr.GetDriverByName('ESRI Shapefile')

      # Set the crs
      latlong = osr.SpatialReference()
      latlong.ImportFromEPSG( 3003 )

      if os.path.exists('/path/mypoints.shp'):
      shpDriver.DeleteDataSource('/path/mypoints.shp')

      outDataSource = shpDriver.CreateDataSource('/path/mypoints.shp')
      outLayer = outDataSource.CreateLayer('', srs=latlong, geom_type=ogr.wkbMultiPoint)
      outLayer.CreateField(ogr.FieldDefn('id', ogr.OFTInteger))
      outDefn = outLayer.GetLayerDefn()
      outFeature = ogr.Feature(outDefn)
      outFeature.SetField('id', 1)
      outFeature.SetGeometry(my_points_dataset)
      outLayer.CreateFeature(outFeature)

      # Remove temporary files
      outDataSource.Destroy()





      share|improve this answer


























        0












        0








        0







        I found the solution in gene's answer in
        Writing a shapefile using OGR, from Shapely Geometry - No feature added Error



         # Write point coordinates to Shapefile
        shpDriver = ogr.GetDriverByName('ESRI Shapefile')

        # Set the crs
        latlong = osr.SpatialReference()
        latlong.ImportFromEPSG( 3003 )

        if os.path.exists('/path/mypoints.shp'):
        shpDriver.DeleteDataSource('/path/mypoints.shp')

        outDataSource = shpDriver.CreateDataSource('/path/mypoints.shp')
        outLayer = outDataSource.CreateLayer('', srs=latlong, geom_type=ogr.wkbMultiPoint)
        outLayer.CreateField(ogr.FieldDefn('id', ogr.OFTInteger))
        outDefn = outLayer.GetLayerDefn()
        outFeature = ogr.Feature(outDefn)
        outFeature.SetField('id', 1)
        outFeature.SetGeometry(my_points_dataset)
        outLayer.CreateFeature(outFeature)

        # Remove temporary files
        outDataSource.Destroy()





        share|improve this answer













        I found the solution in gene's answer in
        Writing a shapefile using OGR, from Shapely Geometry - No feature added Error



         # Write point coordinates to Shapefile
        shpDriver = ogr.GetDriverByName('ESRI Shapefile')

        # Set the crs
        latlong = osr.SpatialReference()
        latlong.ImportFromEPSG( 3003 )

        if os.path.exists('/path/mypoints.shp'):
        shpDriver.DeleteDataSource('/path/mypoints.shp')

        outDataSource = shpDriver.CreateDataSource('/path/mypoints.shp')
        outLayer = outDataSource.CreateLayer('', srs=latlong, geom_type=ogr.wkbMultiPoint)
        outLayer.CreateField(ogr.FieldDefn('id', ogr.OFTInteger))
        outDefn = outLayer.GetLayerDefn()
        outFeature = ogr.Feature(outDefn)
        outFeature.SetField('id', 1)
        outFeature.SetGeometry(my_points_dataset)
        outLayer.CreateFeature(outFeature)

        # Remove temporary files
        outDataSource.Destroy()






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Feb 19 at 17:59









        ilFontailFonta

        488311




        488311






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Geographic Information Systems Stack Exchange!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fgis.stackexchange.com%2fquestions%2f312186%2fempty-shapefile-created-with-python-and-gdal%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Щит и меч (фильм) Содержание Названия серий | Сюжет |...

            Венесуэла на летних Олимпийских играх 2000 Содержание Состав...

            Meter-Bus Содержание Параметры шины | Стандартизация |...