Adding Coordinates to shapefile using ArcPyCreating relationship class with ArcPy using GlobalID?Adding Feature Class to Terrain using ArcPy gives ERROR 000800?Select by Location using first points of polylineSpatial selections using Python in ArcGISDataset C:msuryateritory.sd does not exist or is not supported Failed to execute (UploadServiceDefinition)ArcGIS Error: Cannot set input into parameter spatial_referenceConverting dwg to shapefile using arcpy and ArcGIS jsCreateTin_3d fails with ERROR 000800: The value is not a member of <None>Select By Attributes Based on Unique Value in Shapefile gives ERROR 000840?Conversion of CSV to DBF is getting error message, why?

What is the difference between lands and mana?

15% tax on $7.5k earnings. Is that right?

What to do when eye contact makes your coworker uncomfortable?

Make a Bowl of Alphabet Soup

Is there a nicer/politer/more positive alternative for "negates"?

Quoting Keynes in a lecture

How much of a Devil Fruit must be consumed to gain the power?

What kind of floor tile is this?

Taxes on Dividends in a Roth IRA

Are Captain Marvel's powers affected by Thanos breaking the Tesseract and claiming the stone?

Permission on Database

Why can't the Brexit deadlock in the UK parliament be solved with a plurality vote?

C++ copy constructor called at return

Will number of steps recorded on FitBit/any fitness tracker add up distance in PokemonGo?

Non-trope happy ending?

Why is the Sun approximated as a black body at ~ 5800 K?

How to convince somebody that he is fit for something else, but not this job?

Isometries between spherical space forms

How can ping know if my host is down

Can you use Vicious Mockery to win an argument or gain favours?

Temporarily disable WLAN internet access for children, but allow it for adults

Does Doodling or Improvising on the Piano Have Any Benefits?

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

What does Apple's new App Store requirement mean



Adding Coordinates to shapefile using ArcPy


Creating relationship class with ArcPy using GlobalID?Adding Feature Class to Terrain using ArcPy gives ERROR 000800?Select by Location using first points of polylineSpatial selections using Python in ArcGISDataset C:msuryateritory.sd does not exist or is not supported Failed to execute (UploadServiceDefinition)ArcGIS Error: Cannot set input into parameter spatial_referenceConverting dwg to shapefile using arcpy and ArcGIS jsCreateTin_3d fails with ERROR 000800: The value is not a member of <None>Select By Attributes Based on Unique Value in Shapefile gives ERROR 000840?Conversion of CSV to DBF is getting error message, why?













2















I want to add latitude and longitude column and their values in decimal degrees to my shapefile (fishnet). How to use ArcPy for that?



I have added lat and long using arcpy.AddGeometryAttributes_management but the unit I need is degree decimal and I got it in meters. My code is as below:



arcpy.AddGeometryAttributes_management("fish_lyr","CENTROID")


When specifying degree decimal:



arcpy.AddGeometryAttributes_management("fish_lyr","CENTROID","DEGREEDECIMALS")


it gives the following error:



ExecuteError: Failed to execute. Parameters are not valid.
ERROR 000800: The value is not a member of FEET_US | METERS | KILOMETERS | MILES_US | NAUTICAL_MILES | YARDS.
Failed to execute (AddGeometryAttributes).


Also, what command will use if only latitude or only longitude is needed?










share|improve this question



















  • 1





    Add the fields then use da.UpdateCursor with the SHAPE tokens. You need to add a code attempt or your question will likely be put on hold.

    – BERA
    Mar 18 at 6:47












  • @BERA I've just edited the question, could you provide me some example link to use SHAPE tokens

    – lsr729
    Mar 18 at 6:58











  • Please ask only one question per Question.

    – Vince
    Mar 18 at 11:16















2















I want to add latitude and longitude column and their values in decimal degrees to my shapefile (fishnet). How to use ArcPy for that?



I have added lat and long using arcpy.AddGeometryAttributes_management but the unit I need is degree decimal and I got it in meters. My code is as below:



arcpy.AddGeometryAttributes_management("fish_lyr","CENTROID")


When specifying degree decimal:



arcpy.AddGeometryAttributes_management("fish_lyr","CENTROID","DEGREEDECIMALS")


it gives the following error:



ExecuteError: Failed to execute. Parameters are not valid.
ERROR 000800: The value is not a member of FEET_US | METERS | KILOMETERS | MILES_US | NAUTICAL_MILES | YARDS.
Failed to execute (AddGeometryAttributes).


Also, what command will use if only latitude or only longitude is needed?










share|improve this question



















  • 1





    Add the fields then use da.UpdateCursor with the SHAPE tokens. You need to add a code attempt or your question will likely be put on hold.

    – BERA
    Mar 18 at 6:47












  • @BERA I've just edited the question, could you provide me some example link to use SHAPE tokens

    – lsr729
    Mar 18 at 6:58











  • Please ask only one question per Question.

    – Vince
    Mar 18 at 11:16













2












2








2








I want to add latitude and longitude column and their values in decimal degrees to my shapefile (fishnet). How to use ArcPy for that?



I have added lat and long using arcpy.AddGeometryAttributes_management but the unit I need is degree decimal and I got it in meters. My code is as below:



arcpy.AddGeometryAttributes_management("fish_lyr","CENTROID")


When specifying degree decimal:



arcpy.AddGeometryAttributes_management("fish_lyr","CENTROID","DEGREEDECIMALS")


it gives the following error:



ExecuteError: Failed to execute. Parameters are not valid.
ERROR 000800: The value is not a member of FEET_US | METERS | KILOMETERS | MILES_US | NAUTICAL_MILES | YARDS.
Failed to execute (AddGeometryAttributes).


Also, what command will use if only latitude or only longitude is needed?










share|improve this question
















I want to add latitude and longitude column and their values in decimal degrees to my shapefile (fishnet). How to use ArcPy for that?



I have added lat and long using arcpy.AddGeometryAttributes_management but the unit I need is degree decimal and I got it in meters. My code is as below:



arcpy.AddGeometryAttributes_management("fish_lyr","CENTROID")


When specifying degree decimal:



arcpy.AddGeometryAttributes_management("fish_lyr","CENTROID","DEGREEDECIMALS")


it gives the following error:



ExecuteError: Failed to execute. Parameters are not valid.
ERROR 000800: The value is not a member of FEET_US | METERS | KILOMETERS | MILES_US | NAUTICAL_MILES | YARDS.
Failed to execute (AddGeometryAttributes).


Also, what command will use if only latitude or only longitude is needed?







arcpy error-000800






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 18 at 7:09









PolyGeo

53.7k1781244




53.7k1781244










asked Mar 18 at 6:37









lsr729lsr729

244




244







  • 1





    Add the fields then use da.UpdateCursor with the SHAPE tokens. You need to add a code attempt or your question will likely be put on hold.

    – BERA
    Mar 18 at 6:47












  • @BERA I've just edited the question, could you provide me some example link to use SHAPE tokens

    – lsr729
    Mar 18 at 6:58











  • Please ask only one question per Question.

    – Vince
    Mar 18 at 11:16












  • 1





    Add the fields then use da.UpdateCursor with the SHAPE tokens. You need to add a code attempt or your question will likely be put on hold.

    – BERA
    Mar 18 at 6:47












  • @BERA I've just edited the question, could you provide me some example link to use SHAPE tokens

    – lsr729
    Mar 18 at 6:58











  • Please ask only one question per Question.

    – Vince
    Mar 18 at 11:16







1




1





Add the fields then use da.UpdateCursor with the SHAPE tokens. You need to add a code attempt or your question will likely be put on hold.

– BERA
Mar 18 at 6:47






Add the fields then use da.UpdateCursor with the SHAPE tokens. You need to add a code attempt or your question will likely be put on hold.

– BERA
Mar 18 at 6:47














@BERA I've just edited the question, could you provide me some example link to use SHAPE tokens

– lsr729
Mar 18 at 6:58





@BERA I've just edited the question, could you provide me some example link to use SHAPE tokens

– lsr729
Mar 18 at 6:58













Please ask only one question per Question.

– Vince
Mar 18 at 11:16





Please ask only one question per Question.

– Vince
Mar 18 at 11:16










2 Answers
2






active

oldest

votes


















4














You can use the da.UpdateCursor with the SHAPE@ token:



import arcpy

fc = r'C:TestBuildings.shp'
latfield = 'lat'
longfield = 'long'

with arcpy.da.UpdateCursor(fc,['SHAPE@',latfield,longfield]) as cursor:
for row in cursor:
a = arcpy.PointGeometry(row[0].centroid, arcpy.Describe(fc).spatialReference)
b = a.projectAs(arcpy.SpatialReference(4326)).centroid
row[1], row[2] = b.Y, b.X
cursor.updateRow(row)





share|improve this answer






























    0














    In the case where the OP or a future reader can use geopandas instead of arcpy, you would do the following:



    shp = 'C:/users/gis/data/fish.shp'
    gdf = geopandas.read_file(shp)
    (
    gdf.to_crs('init': 'epsg:4326'
    .assign(lon=lambda df: df['geometry'].centroid.x)
    .assign(lat=lambda df: df['geometry'].centroid.y)
    .to_crs(gdf.crs)
    .to_file(shp)
    )





    share|improve this answer

























    • @BERA I forgot to add the coordinate conversion. But I'm well aware that the OP wanted arcpy. If you read initial the premise of my answer, you'll see that I clearly acknowledged that. However, this could be a case of an X-Y problem for a different reader in the future, which case geopandas could make their life much easier.

      – Paul H
      2 days ago












    • In epsg:4326 the first axis (x) is lat, though

      – nmtoken
      2 days ago











    • @mmtoken, With geopandas/shapely, that order doesn't matter. Latitude, then longitude may be how we say these values, but latitude is still the y-direction. When I do this with a shape file near Portland, OR, USA, I get longitude values around -122.75 and latitude values around 45.57, which is what I expect.

      – Paul H
      2 days ago











    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%2f315792%2fadding-coordinates-to-shapefile-using-arcpy%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    4














    You can use the da.UpdateCursor with the SHAPE@ token:



    import arcpy

    fc = r'C:TestBuildings.shp'
    latfield = 'lat'
    longfield = 'long'

    with arcpy.da.UpdateCursor(fc,['SHAPE@',latfield,longfield]) as cursor:
    for row in cursor:
    a = arcpy.PointGeometry(row[0].centroid, arcpy.Describe(fc).spatialReference)
    b = a.projectAs(arcpy.SpatialReference(4326)).centroid
    row[1], row[2] = b.Y, b.X
    cursor.updateRow(row)





    share|improve this answer



























      4














      You can use the da.UpdateCursor with the SHAPE@ token:



      import arcpy

      fc = r'C:TestBuildings.shp'
      latfield = 'lat'
      longfield = 'long'

      with arcpy.da.UpdateCursor(fc,['SHAPE@',latfield,longfield]) as cursor:
      for row in cursor:
      a = arcpy.PointGeometry(row[0].centroid, arcpy.Describe(fc).spatialReference)
      b = a.projectAs(arcpy.SpatialReference(4326)).centroid
      row[1], row[2] = b.Y, b.X
      cursor.updateRow(row)





      share|improve this answer

























        4












        4








        4







        You can use the da.UpdateCursor with the SHAPE@ token:



        import arcpy

        fc = r'C:TestBuildings.shp'
        latfield = 'lat'
        longfield = 'long'

        with arcpy.da.UpdateCursor(fc,['SHAPE@',latfield,longfield]) as cursor:
        for row in cursor:
        a = arcpy.PointGeometry(row[0].centroid, arcpy.Describe(fc).spatialReference)
        b = a.projectAs(arcpy.SpatialReference(4326)).centroid
        row[1], row[2] = b.Y, b.X
        cursor.updateRow(row)





        share|improve this answer













        You can use the da.UpdateCursor with the SHAPE@ token:



        import arcpy

        fc = r'C:TestBuildings.shp'
        latfield = 'lat'
        longfield = 'long'

        with arcpy.da.UpdateCursor(fc,['SHAPE@',latfield,longfield]) as cursor:
        for row in cursor:
        a = arcpy.PointGeometry(row[0].centroid, arcpy.Describe(fc).spatialReference)
        b = a.projectAs(arcpy.SpatialReference(4326)).centroid
        row[1], row[2] = b.Y, b.X
        cursor.updateRow(row)






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Mar 18 at 7:11









        BERABERA

        16.7k62043




        16.7k62043























            0














            In the case where the OP or a future reader can use geopandas instead of arcpy, you would do the following:



            shp = 'C:/users/gis/data/fish.shp'
            gdf = geopandas.read_file(shp)
            (
            gdf.to_crs('init': 'epsg:4326'
            .assign(lon=lambda df: df['geometry'].centroid.x)
            .assign(lat=lambda df: df['geometry'].centroid.y)
            .to_crs(gdf.crs)
            .to_file(shp)
            )





            share|improve this answer

























            • @BERA I forgot to add the coordinate conversion. But I'm well aware that the OP wanted arcpy. If you read initial the premise of my answer, you'll see that I clearly acknowledged that. However, this could be a case of an X-Y problem for a different reader in the future, which case geopandas could make their life much easier.

              – Paul H
              2 days ago












            • In epsg:4326 the first axis (x) is lat, though

              – nmtoken
              2 days ago











            • @mmtoken, With geopandas/shapely, that order doesn't matter. Latitude, then longitude may be how we say these values, but latitude is still the y-direction. When I do this with a shape file near Portland, OR, USA, I get longitude values around -122.75 and latitude values around 45.57, which is what I expect.

              – Paul H
              2 days ago
















            0














            In the case where the OP or a future reader can use geopandas instead of arcpy, you would do the following:



            shp = 'C:/users/gis/data/fish.shp'
            gdf = geopandas.read_file(shp)
            (
            gdf.to_crs('init': 'epsg:4326'
            .assign(lon=lambda df: df['geometry'].centroid.x)
            .assign(lat=lambda df: df['geometry'].centroid.y)
            .to_crs(gdf.crs)
            .to_file(shp)
            )





            share|improve this answer

























            • @BERA I forgot to add the coordinate conversion. But I'm well aware that the OP wanted arcpy. If you read initial the premise of my answer, you'll see that I clearly acknowledged that. However, this could be a case of an X-Y problem for a different reader in the future, which case geopandas could make their life much easier.

              – Paul H
              2 days ago












            • In epsg:4326 the first axis (x) is lat, though

              – nmtoken
              2 days ago











            • @mmtoken, With geopandas/shapely, that order doesn't matter. Latitude, then longitude may be how we say these values, but latitude is still the y-direction. When I do this with a shape file near Portland, OR, USA, I get longitude values around -122.75 and latitude values around 45.57, which is what I expect.

              – Paul H
              2 days ago














            0












            0








            0







            In the case where the OP or a future reader can use geopandas instead of arcpy, you would do the following:



            shp = 'C:/users/gis/data/fish.shp'
            gdf = geopandas.read_file(shp)
            (
            gdf.to_crs('init': 'epsg:4326'
            .assign(lon=lambda df: df['geometry'].centroid.x)
            .assign(lat=lambda df: df['geometry'].centroid.y)
            .to_crs(gdf.crs)
            .to_file(shp)
            )





            share|improve this answer















            In the case where the OP or a future reader can use geopandas instead of arcpy, you would do the following:



            shp = 'C:/users/gis/data/fish.shp'
            gdf = geopandas.read_file(shp)
            (
            gdf.to_crs('init': 'epsg:4326'
            .assign(lon=lambda df: df['geometry'].centroid.x)
            .assign(lat=lambda df: df['geometry'].centroid.y)
            .to_crs(gdf.crs)
            .to_file(shp)
            )






            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited 2 days ago

























            answered 2 days ago









            Paul HPaul H

            324211




            324211












            • @BERA I forgot to add the coordinate conversion. But I'm well aware that the OP wanted arcpy. If you read initial the premise of my answer, you'll see that I clearly acknowledged that. However, this could be a case of an X-Y problem for a different reader in the future, which case geopandas could make their life much easier.

              – Paul H
              2 days ago












            • In epsg:4326 the first axis (x) is lat, though

              – nmtoken
              2 days ago











            • @mmtoken, With geopandas/shapely, that order doesn't matter. Latitude, then longitude may be how we say these values, but latitude is still the y-direction. When I do this with a shape file near Portland, OR, USA, I get longitude values around -122.75 and latitude values around 45.57, which is what I expect.

              – Paul H
              2 days ago


















            • @BERA I forgot to add the coordinate conversion. But I'm well aware that the OP wanted arcpy. If you read initial the premise of my answer, you'll see that I clearly acknowledged that. However, this could be a case of an X-Y problem for a different reader in the future, which case geopandas could make their life much easier.

              – Paul H
              2 days ago












            • In epsg:4326 the first axis (x) is lat, though

              – nmtoken
              2 days ago











            • @mmtoken, With geopandas/shapely, that order doesn't matter. Latitude, then longitude may be how we say these values, but latitude is still the y-direction. When I do this with a shape file near Portland, OR, USA, I get longitude values around -122.75 and latitude values around 45.57, which is what I expect.

              – Paul H
              2 days ago

















            @BERA I forgot to add the coordinate conversion. But I'm well aware that the OP wanted arcpy. If you read initial the premise of my answer, you'll see that I clearly acknowledged that. However, this could be a case of an X-Y problem for a different reader in the future, which case geopandas could make their life much easier.

            – Paul H
            2 days ago






            @BERA I forgot to add the coordinate conversion. But I'm well aware that the OP wanted arcpy. If you read initial the premise of my answer, you'll see that I clearly acknowledged that. However, this could be a case of an X-Y problem for a different reader in the future, which case geopandas could make their life much easier.

            – Paul H
            2 days ago














            In epsg:4326 the first axis (x) is lat, though

            – nmtoken
            2 days ago





            In epsg:4326 the first axis (x) is lat, though

            – nmtoken
            2 days ago













            @mmtoken, With geopandas/shapely, that order doesn't matter. Latitude, then longitude may be how we say these values, but latitude is still the y-direction. When I do this with a shape file near Portland, OR, USA, I get longitude values around -122.75 and latitude values around 45.57, which is what I expect.

            – Paul H
            2 days ago






            @mmtoken, With geopandas/shapely, that order doesn't matter. Latitude, then longitude may be how we say these values, but latitude is still the y-direction. When I do this with a shape file near Portland, OR, USA, I get longitude values around -122.75 and latitude values around 45.57, which is what I expect.

            – Paul H
            2 days ago


















            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%2f315792%2fadding-coordinates-to-shapefile-using-arcpy%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

            Marja Vauras Lähteet | Aiheesta muualla | NavigointivalikkoMarja Vauras Turun yliopiston tutkimusportaalissaInfobox OKSuomalaisen Tiedeakatemian varsinaiset jäsenetKasvatustieteiden tiedekunnan dekaanit ja muu johtoMarja VaurasKoulutusvienti on kestävyys- ja ketteryyslaji (2.5.2017)laajentamallaWorldCat Identities0000 0001 0855 9405n86069603utb201588738523620927

            Which is better: GPT or RelGAN for text generation?2019 Community Moderator ElectionWhat is the difference between TextGAN and LM for text generation?GANs (generative adversarial networks) possible for text as well?Generator loss not decreasing- text to image synthesisChoosing a right algorithm for template-based text generationHow should I format input and output for text generation with LSTMsGumbel Softmax vs Vanilla Softmax for GAN trainingWhich neural network to choose for classification from text/speech?NLP text autoencoder that generates text in poetic meterWhat is the interpretation of the expectation notation in the GAN formulation?What is the difference between TextGAN and LM for text generation?How to prepare the data for text generation task

            Is this part of the description of the Archfey warlock's Misty Escape feature redundant?When is entropic ward considered “used”?How does the reaction timing work for Wrath of the Storm? Can it potentially prevent the damage from the triggering attack?Does the Dark Arts Archlich warlock patrons's Arcane Invisibility activate every time you cast a level 1+ spell?When attacking while invisible, when exactly does invisibility break?Can I cast Hellish Rebuke on my turn?Do I have to “pre-cast” a reaction spell in order for it to be triggered?What happens if a Player Misty Escapes into an Invisible CreatureCan a reaction interrupt multiattack?Does the Fiend-patron warlock's Hurl Through Hell feature dispel effects that require the target to be on the same plane as the caster?What are you allowed to do while using the Warlock's Eldritch Master feature?