Python script for calculating the area of a polygonHow do I calculate polygon area with arcobjects?Calculate...

Are all power cords made equal?

Why is Shelob considered evil?

What does @ mean in a hostname in DNS configuration?

Why is the meaning of kanji 閑 "leisure"?

Does this property characterize the odd primes?

What does it mean when an external ID field follows a DML Statement?

Can I do anything else with aspersions other than cast them?

What does "don't have a baby" imply or mean in this sentence?

Coworker is trying to get me to sign his petition to run for office. How to decline politely?

Do these large-scale, human power-plant-tending robots from the Matrix movies have a name, in-universe or out?

What is the name of this perspective and how is it constructed?

How to modify 'inter arma enim silent leges' to mean 'in a time of crisis, the law falls silent'?

Why do we interpret the accelerated expansion of the universe as the proof for the existence of dark energy?

Fundamental Theorem of Calculus I help!

Is layered encryption more secure than long passwords?

In the Lost in Space intro why was Dr. Smith actor listed as a special guest star?

Identical projects by students at two different colleges: still plagiarism?

Can a planet be tidally unlocked?

A cancellation property for permutations

How can guns be countered by melee combat without raw-ability or exceptional explanations?

Will linear voltage regulator step up current?

Cryptic cross... with words

Taking an academic pseudonym?

Found a major flaw in paper from home university – to which I would like to return



Python script for calculating the area of a polygon


How do I calculate polygon area with arcobjects?Calculate area within Python script in ArcMapArea of an EPSG 27700 polygonCalculating area of polygon inside region?largest area polygonCalculating relative share of area covered by water/percentage of polygon area that overlaps in ArcGIS for Desktop?Calculating area of polygon within Buffers in ArcGIS for Desktop?Calculating area of user defined polygon in openstreetmap using pythonCalculating polygon area inside another polygon in QGISCalculating polygon area within polygons in QGIS?













0















enter image description hereI am looking for a python code for this polygon. I need to calculate the area inside this polygon and I am new to programming. (Very new). Can anybody assist me with this? I have to use a python code for this, I cannot use any other means.










share|improve this question




















  • 1





    Your title mentions Perimeter and yet your question asks about Area. In any event, if your polygon is in a file geodatabase you should be able to read both from the attribute table, or if it is in a shapefile just add two fields and use Calculate Geometry.

    – PolyGeo
    Apr 30 '15 at 23:53











  • Hi, yea I meant to say calculate the area inside the polygon. I was able to show the area just by using the measurement tool. The problem is that I have to show a python code for this process.

    – user51399
    Apr 30 '15 at 23:57






  • 2





    As an added bonus the Calculate Geometry will do perimeter or area in a different spatial reference and several units... particularly handy if you data is in WGS84 and you need to know how many acres it is, without having to remember how many square feet is it in an acre. There's a discourse on how to do it in python here help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//…

    – Michael Stimson
    Apr 30 '15 at 23:59













  • Please use the edit button to provide clarifications/corrections to your question. The parts of a question are described at meta.gis.stackexchange.com/a/3353. I suspect Python code to do this will involve using a SearchCursor the read the aforementioned fields.

    – PolyGeo
    Apr 30 '15 at 23:59


















0















enter image description hereI am looking for a python code for this polygon. I need to calculate the area inside this polygon and I am new to programming. (Very new). Can anybody assist me with this? I have to use a python code for this, I cannot use any other means.










share|improve this question




















  • 1





    Your title mentions Perimeter and yet your question asks about Area. In any event, if your polygon is in a file geodatabase you should be able to read both from the attribute table, or if it is in a shapefile just add two fields and use Calculate Geometry.

    – PolyGeo
    Apr 30 '15 at 23:53











  • Hi, yea I meant to say calculate the area inside the polygon. I was able to show the area just by using the measurement tool. The problem is that I have to show a python code for this process.

    – user51399
    Apr 30 '15 at 23:57






  • 2





    As an added bonus the Calculate Geometry will do perimeter or area in a different spatial reference and several units... particularly handy if you data is in WGS84 and you need to know how many acres it is, without having to remember how many square feet is it in an acre. There's a discourse on how to do it in python here help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//…

    – Michael Stimson
    Apr 30 '15 at 23:59













  • Please use the edit button to provide clarifications/corrections to your question. The parts of a question are described at meta.gis.stackexchange.com/a/3353. I suspect Python code to do this will involve using a SearchCursor the read the aforementioned fields.

    – PolyGeo
    Apr 30 '15 at 23:59
















0












0








0








enter image description hereI am looking for a python code for this polygon. I need to calculate the area inside this polygon and I am new to programming. (Very new). Can anybody assist me with this? I have to use a python code for this, I cannot use any other means.










share|improve this question
















enter image description hereI am looking for a python code for this polygon. I need to calculate the area inside this polygon and I am new to programming. (Very new). Can anybody assist me with this? I have to use a python code for this, I cannot use any other means.







arcpy polygon area






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jul 5 '17 at 7:02









Fezter

16.6k105398




16.6k105398










asked Apr 30 '15 at 23:43







user51399















  • 1





    Your title mentions Perimeter and yet your question asks about Area. In any event, if your polygon is in a file geodatabase you should be able to read both from the attribute table, or if it is in a shapefile just add two fields and use Calculate Geometry.

    – PolyGeo
    Apr 30 '15 at 23:53











  • Hi, yea I meant to say calculate the area inside the polygon. I was able to show the area just by using the measurement tool. The problem is that I have to show a python code for this process.

    – user51399
    Apr 30 '15 at 23:57






  • 2





    As an added bonus the Calculate Geometry will do perimeter or area in a different spatial reference and several units... particularly handy if you data is in WGS84 and you need to know how many acres it is, without having to remember how many square feet is it in an acre. There's a discourse on how to do it in python here help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//…

    – Michael Stimson
    Apr 30 '15 at 23:59













  • Please use the edit button to provide clarifications/corrections to your question. The parts of a question are described at meta.gis.stackexchange.com/a/3353. I suspect Python code to do this will involve using a SearchCursor the read the aforementioned fields.

    – PolyGeo
    Apr 30 '15 at 23:59
















  • 1





    Your title mentions Perimeter and yet your question asks about Area. In any event, if your polygon is in a file geodatabase you should be able to read both from the attribute table, or if it is in a shapefile just add two fields and use Calculate Geometry.

    – PolyGeo
    Apr 30 '15 at 23:53











  • Hi, yea I meant to say calculate the area inside the polygon. I was able to show the area just by using the measurement tool. The problem is that I have to show a python code for this process.

    – user51399
    Apr 30 '15 at 23:57






  • 2





    As an added bonus the Calculate Geometry will do perimeter or area in a different spatial reference and several units... particularly handy if you data is in WGS84 and you need to know how many acres it is, without having to remember how many square feet is it in an acre. There's a discourse on how to do it in python here help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//…

    – Michael Stimson
    Apr 30 '15 at 23:59













  • Please use the edit button to provide clarifications/corrections to your question. The parts of a question are described at meta.gis.stackexchange.com/a/3353. I suspect Python code to do this will involve using a SearchCursor the read the aforementioned fields.

    – PolyGeo
    Apr 30 '15 at 23:59










1




1





Your title mentions Perimeter and yet your question asks about Area. In any event, if your polygon is in a file geodatabase you should be able to read both from the attribute table, or if it is in a shapefile just add two fields and use Calculate Geometry.

– PolyGeo
Apr 30 '15 at 23:53





Your title mentions Perimeter and yet your question asks about Area. In any event, if your polygon is in a file geodatabase you should be able to read both from the attribute table, or if it is in a shapefile just add two fields and use Calculate Geometry.

– PolyGeo
Apr 30 '15 at 23:53













Hi, yea I meant to say calculate the area inside the polygon. I was able to show the area just by using the measurement tool. The problem is that I have to show a python code for this process.

– user51399
Apr 30 '15 at 23:57





Hi, yea I meant to say calculate the area inside the polygon. I was able to show the area just by using the measurement tool. The problem is that I have to show a python code for this process.

– user51399
Apr 30 '15 at 23:57




2




2





As an added bonus the Calculate Geometry will do perimeter or area in a different spatial reference and several units... particularly handy if you data is in WGS84 and you need to know how many acres it is, without having to remember how many square feet is it in an acre. There's a discourse on how to do it in python here help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//…

– Michael Stimson
Apr 30 '15 at 23:59







As an added bonus the Calculate Geometry will do perimeter or area in a different spatial reference and several units... particularly handy if you data is in WGS84 and you need to know how many acres it is, without having to remember how many square feet is it in an acre. There's a discourse on how to do it in python here help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//…

– Michael Stimson
Apr 30 '15 at 23:59















Please use the edit button to provide clarifications/corrections to your question. The parts of a question are described at meta.gis.stackexchange.com/a/3353. I suspect Python code to do this will involve using a SearchCursor the read the aforementioned fields.

– PolyGeo
Apr 30 '15 at 23:59







Please use the edit button to provide clarifications/corrections to your question. The parts of a question are described at meta.gis.stackexchange.com/a/3353. I suspect Python code to do this will involve using a SearchCursor the read the aforementioned fields.

– PolyGeo
Apr 30 '15 at 23:59












3 Answers
3






active

oldest

votes


















7














Here's an example of how you could get the area using a search cursor:



polygon_layer = "C:\Polygon.shp"

with arcpy.da.SearchCursor(polygon_layer, ("OID@", "SHAPE@")) as search_cursor:
for row in search_cursor:
oid = row[0]
geometry = row[1]

print "OID {0}: area is {1}".format(oid, geometry.area)





share|improve this answer


























  • Could use the 'SHAPE@AREA' token too, and will be a bit faster.

    – DWynne
    May 4 '15 at 16:27





















0














import os
from osgeo import ogr

daShapefile = r"C:Usersnew1.shp" #path where your shape file is present

driver = ogr.GetDriverByName('ESRI Shapefile')

dataSource = driver.Open(daShapefile,1) # 0 means read-only. 1 means writeable.

# Check to see if shapefile is found.
if dataSource is None:
print 'Could not open %s' % (daShapefile)
else:
print 'Opened %s' % (daShapefile)
layer = dataSource.GetLayer()
featureCount = layer.GetFeatureCount()
print "Number of features in %s: %d" % (os.path.basename(daShapefile),featureCount)
print "n"


new_field = ogr.FieldDefn("Area", ogr.OFTReal)
new_field.SetWidth(32)
new_field.SetPrecision(2) #added line to set precision
layer.CreateField(new_field)

for feature in layer:
geom = feature.GetGeometryRef()
area = geom.GetArea()
print area
feature.SetField("Area", area)
layer.SetFeature(feature)


'''
this code here finds the area of the polygons present in your shape file and adds a field named "Area" to your database with the value of the area of each polygon






share|improve this answer

































    0














    same as the accepted answer but it is a one-liner.



    area = arcpy.da.FeatureClassToNumPyArray(polygon_layer, 'SHAPE@AREA')[0][0]





    share








    New contributor




    dfresh22 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
    Check out our Code of Conduct.




















      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%2f144734%2fpython-script-for-calculating-the-area-of-a-polygon%23new-answer', 'question_page');
      }
      );

      Post as a guest















      Required, but never shown
























      3 Answers
      3






      active

      oldest

      votes








      3 Answers
      3






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      7














      Here's an example of how you could get the area using a search cursor:



      polygon_layer = "C:\Polygon.shp"

      with arcpy.da.SearchCursor(polygon_layer, ("OID@", "SHAPE@")) as search_cursor:
      for row in search_cursor:
      oid = row[0]
      geometry = row[1]

      print "OID {0}: area is {1}".format(oid, geometry.area)





      share|improve this answer


























      • Could use the 'SHAPE@AREA' token too, and will be a bit faster.

        – DWynne
        May 4 '15 at 16:27


















      7














      Here's an example of how you could get the area using a search cursor:



      polygon_layer = "C:\Polygon.shp"

      with arcpy.da.SearchCursor(polygon_layer, ("OID@", "SHAPE@")) as search_cursor:
      for row in search_cursor:
      oid = row[0]
      geometry = row[1]

      print "OID {0}: area is {1}".format(oid, geometry.area)





      share|improve this answer


























      • Could use the 'SHAPE@AREA' token too, and will be a bit faster.

        – DWynne
        May 4 '15 at 16:27
















      7












      7








      7







      Here's an example of how you could get the area using a search cursor:



      polygon_layer = "C:\Polygon.shp"

      with arcpy.da.SearchCursor(polygon_layer, ("OID@", "SHAPE@")) as search_cursor:
      for row in search_cursor:
      oid = row[0]
      geometry = row[1]

      print "OID {0}: area is {1}".format(oid, geometry.area)





      share|improve this answer















      Here's an example of how you could get the area using a search cursor:



      polygon_layer = "C:\Polygon.shp"

      with arcpy.da.SearchCursor(polygon_layer, ("OID@", "SHAPE@")) as search_cursor:
      for row in search_cursor:
      oid = row[0]
      geometry = row[1]

      print "OID {0}: area is {1}".format(oid, geometry.area)






      share|improve this answer














      share|improve this answer



      share|improve this answer








      edited May 1 '15 at 0:12

























      answered May 1 '15 at 0:07









      ianbroadianbroad

      7,43233374




      7,43233374













      • Could use the 'SHAPE@AREA' token too, and will be a bit faster.

        – DWynne
        May 4 '15 at 16:27





















      • Could use the 'SHAPE@AREA' token too, and will be a bit faster.

        – DWynne
        May 4 '15 at 16:27



















      Could use the 'SHAPE@AREA' token too, and will be a bit faster.

      – DWynne
      May 4 '15 at 16:27







      Could use the 'SHAPE@AREA' token too, and will be a bit faster.

      – DWynne
      May 4 '15 at 16:27















      0














      import os
      from osgeo import ogr

      daShapefile = r"C:Usersnew1.shp" #path where your shape file is present

      driver = ogr.GetDriverByName('ESRI Shapefile')

      dataSource = driver.Open(daShapefile,1) # 0 means read-only. 1 means writeable.

      # Check to see if shapefile is found.
      if dataSource is None:
      print 'Could not open %s' % (daShapefile)
      else:
      print 'Opened %s' % (daShapefile)
      layer = dataSource.GetLayer()
      featureCount = layer.GetFeatureCount()
      print "Number of features in %s: %d" % (os.path.basename(daShapefile),featureCount)
      print "n"


      new_field = ogr.FieldDefn("Area", ogr.OFTReal)
      new_field.SetWidth(32)
      new_field.SetPrecision(2) #added line to set precision
      layer.CreateField(new_field)

      for feature in layer:
      geom = feature.GetGeometryRef()
      area = geom.GetArea()
      print area
      feature.SetField("Area", area)
      layer.SetFeature(feature)


      '''
      this code here finds the area of the polygons present in your shape file and adds a field named "Area" to your database with the value of the area of each polygon






      share|improve this answer






























        0














        import os
        from osgeo import ogr

        daShapefile = r"C:Usersnew1.shp" #path where your shape file is present

        driver = ogr.GetDriverByName('ESRI Shapefile')

        dataSource = driver.Open(daShapefile,1) # 0 means read-only. 1 means writeable.

        # Check to see if shapefile is found.
        if dataSource is None:
        print 'Could not open %s' % (daShapefile)
        else:
        print 'Opened %s' % (daShapefile)
        layer = dataSource.GetLayer()
        featureCount = layer.GetFeatureCount()
        print "Number of features in %s: %d" % (os.path.basename(daShapefile),featureCount)
        print "n"


        new_field = ogr.FieldDefn("Area", ogr.OFTReal)
        new_field.SetWidth(32)
        new_field.SetPrecision(2) #added line to set precision
        layer.CreateField(new_field)

        for feature in layer:
        geom = feature.GetGeometryRef()
        area = geom.GetArea()
        print area
        feature.SetField("Area", area)
        layer.SetFeature(feature)


        '''
        this code here finds the area of the polygons present in your shape file and adds a field named "Area" to your database with the value of the area of each polygon






        share|improve this answer




























          0












          0








          0







          import os
          from osgeo import ogr

          daShapefile = r"C:Usersnew1.shp" #path where your shape file is present

          driver = ogr.GetDriverByName('ESRI Shapefile')

          dataSource = driver.Open(daShapefile,1) # 0 means read-only. 1 means writeable.

          # Check to see if shapefile is found.
          if dataSource is None:
          print 'Could not open %s' % (daShapefile)
          else:
          print 'Opened %s' % (daShapefile)
          layer = dataSource.GetLayer()
          featureCount = layer.GetFeatureCount()
          print "Number of features in %s: %d" % (os.path.basename(daShapefile),featureCount)
          print "n"


          new_field = ogr.FieldDefn("Area", ogr.OFTReal)
          new_field.SetWidth(32)
          new_field.SetPrecision(2) #added line to set precision
          layer.CreateField(new_field)

          for feature in layer:
          geom = feature.GetGeometryRef()
          area = geom.GetArea()
          print area
          feature.SetField("Area", area)
          layer.SetFeature(feature)


          '''
          this code here finds the area of the polygons present in your shape file and adds a field named "Area" to your database with the value of the area of each polygon






          share|improve this answer















          import os
          from osgeo import ogr

          daShapefile = r"C:Usersnew1.shp" #path where your shape file is present

          driver = ogr.GetDriverByName('ESRI Shapefile')

          dataSource = driver.Open(daShapefile,1) # 0 means read-only. 1 means writeable.

          # Check to see if shapefile is found.
          if dataSource is None:
          print 'Could not open %s' % (daShapefile)
          else:
          print 'Opened %s' % (daShapefile)
          layer = dataSource.GetLayer()
          featureCount = layer.GetFeatureCount()
          print "Number of features in %s: %d" % (os.path.basename(daShapefile),featureCount)
          print "n"


          new_field = ogr.FieldDefn("Area", ogr.OFTReal)
          new_field.SetWidth(32)
          new_field.SetPrecision(2) #added line to set precision
          layer.CreateField(new_field)

          for feature in layer:
          geom = feature.GetGeometryRef()
          area = geom.GetArea()
          print area
          feature.SetField("Area", area)
          layer.SetFeature(feature)


          '''
          this code here finds the area of the polygons present in your shape file and adds a field named "Area" to your database with the value of the area of each polygon







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Jul 5 '17 at 6:17









          LaughU

          3,16441232




          3,16441232










          answered Jul 5 '17 at 5:57









          asteriskasterisk

          1




          1























              0














              same as the accepted answer but it is a one-liner.



              area = arcpy.da.FeatureClassToNumPyArray(polygon_layer, 'SHAPE@AREA')[0][0]





              share








              New contributor




              dfresh22 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
              Check out our Code of Conduct.

























                0














                same as the accepted answer but it is a one-liner.



                area = arcpy.da.FeatureClassToNumPyArray(polygon_layer, 'SHAPE@AREA')[0][0]





                share








                New contributor




                dfresh22 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                Check out our Code of Conduct.























                  0












                  0








                  0







                  same as the accepted answer but it is a one-liner.



                  area = arcpy.da.FeatureClassToNumPyArray(polygon_layer, 'SHAPE@AREA')[0][0]





                  share








                  New contributor




                  dfresh22 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                  Check out our Code of Conduct.










                  same as the accepted answer but it is a one-liner.



                  area = arcpy.da.FeatureClassToNumPyArray(polygon_layer, 'SHAPE@AREA')[0][0]






                  share








                  New contributor




                  dfresh22 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                  Check out our Code of Conduct.








                  share


                  share






                  New contributor




                  dfresh22 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                  Check out our Code of Conduct.









                  answered 59 secs ago









                  dfresh22dfresh22

                  1012




                  1012




                  New contributor




                  dfresh22 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                  Check out our Code of Conduct.





                  New contributor





                  dfresh22 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                  Check out our Code of Conduct.






                  dfresh22 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                  Check out our Code of Conduct.






























                      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%2f144734%2fpython-script-for-calculating-the-area-of-a-polygon%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 Содержание Параметры шины | Стандартизация |...