Hot answers tagged

72

Make the layer editable, then use the field calculator (Layer>Open attribute table>Field Calculator/Ctrl+I or right click shapefile>Open attribute table>Field Calculator/Ctrl+I). There is an operator "$area" that will calculate the area of each row in the table. All units will be calculated in the units of the projection, so you probably want to project it ...


29

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 ...


26

Open field calculator, select the new column and type the following expression For area: $area For perimeter: $perimeter Make sure your layer is in a projected coordinate system (not lat/long ) and in correct units. ( i.e. if your layer's projection has 'meters' as units, your area will be square meters ) Note that reprojecting layers on-the-fly does not ...


23

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 ...


19

This can also be done with Vector|Geometry Tools|Add/export geometry columns, which creates a new shapefile with area and perimeter (or length) columns added. Edit: (using the tool above, you can also unselect "save as new shape-file" in V1.8, the shapefile is now only updated!) Using the field calculator is probably a better idea, though, as it doesn't ...


19

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, ...


18

Google Maps Mania blog points to example of Swiss Administrative Boundaries Map: The code from Vasile is on github.


18

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


17

I found a function to return the UTM zone for any point on the PostGIS wiki: utmzone() Using that you could do: SELECT ST_Area( ST_Transform(the_geom, utmzone(ST_Centroid(the_geom)) )) FROM polygons WHERE... HTH, Micha


17

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 ...


15

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 ...


13

It is a consequence of a theorem of Archimedes (c. 287-212 BCE) that for a spherical model of the earth, the area of a cell spanning longitudes l0 to l1 (l1 > l0) and latitudes f0 to f1 (f1 > f0) equals (sin(f1) - sin(f0)) * (l1 - l0) * R^2 where l0 and l1 are expressed in radians (not degrees or whatever). l1 - l0 is calculated modulo 2*pi (e.g., -179 - ...


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 ...


10

I generally use the character ² or U+00B2. So it is km², without requiring any special formatting. If you have a MS Windows keyboard, type the sequence: Alt+0178 Other platforms have different ways of typing this character. You can also copy/paste the Unicode character. More info: http://www.fileformat.info/info/unicode/char/b2/index.htm


10

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 ...


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

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

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 ...


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)


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