Hot answers tagged

30

There are three different ways to find and store polygon area into a feature class with arcpy: 1) field calculator, 2) "classic" arcpy cursors, and 3) arcpy.da cursors. Some of this is borrowed from my previous answer about using SearchCursor. 1. Field calculator When using field calculator, there are three different expression types that use different ...


25

I would try the Union tool with NO_GAPS: NO_GAPS —A feature will be created for the areas in the output that are completely enclosed by polygons. This feature will have blank attributes. You can then select the features with blank attributes below a threshold size and calculate their attributes to be the same as the original polygon - or copy/paste ...


24

It wasn't readily apparent to me how to use @sgillies answer, so here is a more verbose version: import pyproj import shapely import shapely.ops as ops from shapely.geometry.polygon import Polygon from functools import partial geom = Polygon([(0, 0), (0, 10), (10, 10), (10, 0), (0, 0)]) geom_area = ops.transform( partial( pyproj.transform, ...


20

You can do library(raster) x <- shapefile('file.shp') crs(x) x$area_sqkm <- area(x) / 1000000 Assuming that your crs is longitude/latitude, or with meter as distance unit


20

If the crs of the GeoDataFrame is known (EPSG:4326 unit=degree, here), you don't need Shapely, nor pyproj in your script because GeoPandas uses them). import geopandas as gpd test = gpd.read_file("test_wgs84.shp") print test.crs test.head(2) Now copy your GeoDataFrame and change the projection to a Cartesian system (EPSG:3857, unit= m as in the answer of ...


16

It looks like your coordinates are longitude and latitude, yes? Use Shapely's shapely.ops.transform function to transform the polygon to projected equal area coordinates and then take the area. python import pyproj from functools import partial geom_aea = transform( partial( pyproj.transform, pyproj.Proj(init='EPSG:4326'), pyproj.Proj( ...


15

All recent versions of ArcGIS cheat -- the underlying shape type knows when it was generated as a circle, and reports a perfect circle area, even when the vertex count would make it an octagon. I just whipped up some test code using the ArcSDE 'C' API and got the following results (all generated as a circle from point {0,100000} in PCS_WGS_1984_UTM_32N): ...


15

There's a special field in OGR SQL called OGR_GEOM_AREA which returns the area of the feature's geometry: ogrinfo -sql "SELECT SUM(OGR_GEOM_AREA) AS TOTAL_AREA FROM myshapefile" myshapefile.shp where TOTAL_AREA unit of measure depends by the layer SRS (read the comments below).


14

There is a relatively simple exact formula for the area of any spherical quadrangle bounded by parallels (lines of latitude) and meridians (lines of longitude). It can be derived straightforwardly using basic properties of the ellipse (of major axis a and minor axis b) that is rotated around its minor axis to produce the ellipsoid. (The derivation makes a ...


12

By design Shapely is unaware of coordinate reference systems or units. To use it to solve real world problems, you must learn to transform longitude and latitude to an approximately planar local reference system (like a US State Plane) and you must keep track of your own units. I use pyproj to do this, but you can use whatever you want. Once you've ...


12

Can you provide data for an example? Anyways, try this: library(sf) f <- st_read("shapefile.shp") f$area <- st_area(f) #Take care of units Best


11

Generally to calculate the area of a bbox in a projected coordinate system since it's a (big) rectangle you can use the area formula : area = (sw_longitude - ne_longitude) * (sw_latitude - ne_latitude) Depending now on your spatial location (ie you're in a projected crs) the above formula will give you square mapunits (km^2, m^2 whatever). In case you'...


11

You can use the AutoFields plugin, which solves exactly that issue. Go to the plugin's docked window, select your polygon layer, choose the 'Area' field from the list of existing fields, choose the expression 'Area' and click on Save AutoFields. Now QGIS will maintain your Area field up-to-date when you create new polygons or edit existing ones (you can ...


9

As MappaGnosis indicated, you could write a little script for this. Here's one called polygonbuffer which takes three arguments: The output file name, the radius of your buffer, and the number of corners of the polygons. Open a Python console in QGIS, paste the script and press enter to define the function, then call using something like polygonbuffer("...


9

You are doing nothing wrong: In QGIS Lisboa and 2.1.0 (dev) the areas calculate perfectly, in QGIS 2.01-3 (standalone) not. This is a known QGIS 2.0.1 bug and has a ticket: https://hub.qgis.org/issues/9031 Simply turn off On-the-fly-reprojection while calculating the new field, or try again with the latest dev build from OSGEO4W.


9

There are two ways of calculating, raster on raster or vector on vector. radouxju has given an instruction on raster on raster but I believe the vector on vector might be more what you're after. Convert your raster into polygons using Raster to Polygon, don't simplify the polygons for more accurate results. Percentage of cover for the overlaying polygons ...


9

Use my script from Checking if polygon fits inside another polygon using ArcGIS or QGIS? to create points inside your polygons. Each point is a centre of maximum inscribed circle of the parcel. Please note, script tested on shapefiles only and it does not handle polygons with holes, i.e. donut like polygons. Table of centre point contains field theDist, ...


9

There are 2 approaches: 1/ select all area's which has no value ("Area" is null) and do the calculation just on the selected ones. Check 'only update XXX selected features' and 'update existing field' 2/ You can make a virtual field with the expression $area. Every time you add a feature the area will be calculated. Warning: a virtual field is project ...


8

You have to set your Project CRS also to UTM fuseau 35 Sud (Settings/Project Settings/CRS). CRS for shapefile and project may differ, but measuring is always done in project CRS.


8

For the Project coordinate reference system, you have to choose a projected CRS, which uses real metres as units. Openlayers Plugin uses Google mercator, which is only corresponding to real meters at the aequator. The further north you come, the more distorted the length units are (look at Greenland in Openstreetmap, it is not so big in reality). By ...


8

PolyGeo's solution is one I have employed myself and works well (+1). Another alternative is to buffer your polygons by a small amount and then de-buffer the result by the same amount (say +1m and then -1m). This also works well but carries a small risk of accidentally joining polygons that neighbour by the same amount as your buffer. It can also increase ...


8

You can use "Eliminate Polygon Part" tool (Data Management Tools -> Generalization) in ArcToolbox. You can specify minimum hole area/percentage to remove.


8

In the conversion world, what you've built is known as a "bowtie". If you really want that shape, you need to conform to topology rules by making a multipart polygon with "left hand rule" part vertices {0,0},{0.5,0.5},{0,1},{0,0} and {0.5,0.5},{1,0},{1,1},{0.5,0.5} (reverse the order [or just swap vertices 2 & 3 in each part] to generate "right hand ...


8

The quickest way that I am aware of, is to use the Shapely library (requires the GEOS Engine, you can find a one-click installer for shapely here if you're on windows) The manual provides a dead-on example of what your question: >>> from shapely.geometry import Point >>> a = Point(1, 1).buffer(1.5) >>> b = Point(2, 1).buffer(1....


8

It is correct to use an equal area projection in order to compute the area of your polygon. However, in your case, you should be aware that only the vertices of a polygon are projected when you change the coordinate system. Between the vertices, straight lines are then interpolated (but if you have a huge polygons, those lines should have been curves), ...


8

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)


8

ST_Intersection(geomA, geomB) returns a geometry, then calculate areas with ST_Area.


8

Yes, it is possible, but you need to use the OGR SQLite dialect as follows: ogrinfo -dialect SQLite -sql 'SELECT SUM(ST_Area(geometry))/10000 FROM myshapefile' myshapefile.shp Also, ensure that myshapefile is the layer name in myshapefile.shp. You can do this as follows: ogrinfo myshapefile.shp INFO: Open of `myshapefile.shp` using driver `ESRI ...


7

You have a closing paren in the wrong place towards the end of your query. I tried this and got a NaN return, SELECT ST_AREA(ST_Transform(ST_GeomFromText('POLYGON((871325.790874952 6105405.3261047,871418.748307692 6105359.72944624,871346.22022442 6105215.141258,871254.85408906 6105261.72007212,871325.790874952 6105405.3261047))',4326),31467)) As sqm; The ...


7

with 3 steps you can achieve what you want: Vectorize raster based on the values you want to calculate Open your new vector, and create a new column. Name it 'Area'. Use the field calculator to populate the column with the variable $area


Only top voted, non community-wiki answers of a minimum length are eligible