What is the units of distance_col and max_distance in geopandas sjoin_nearest? - gis

geopandas.sjoin_nearest takes parameters max_distance and distance_col. What is the units of the distances / how do I interpret them? Is it degrees?
https://geopandas.org/en/stable/docs/reference/api/geopandas.sjoin_nearest.html#geopandas.sjoin_nearest

While geopandas provides utilities for converting between coordinate systems (e.g. to_crs), most operations in geopandas ignore the projection information. Spatial operations such as distance, area, buffer, etc. are done in whatever units the geometries are in. If your geometries are in meters, these will be in meters. If they're in degrees, they'll be in degrees.
For example, let's take a look at the natural earth dataset. You can see that the geometry column is in lat/lon coordinates by just looking at the values:
In [1]: import geopandas as gpd
In [2]: gdf = gpd.read_file(gpd.datasets.get_path('naturalearth_lowres'))
In [3]: gdf
Out[3]:
pop_est continent name iso_a3 gdp_md_est geometry
0 920938 Oceania Fiji FJI 8374.0 MULTIPOLYGON (((180.00000 -16.06713, 180.00000...
1 53950935 Africa Tanzania TZA 150600.0 POLYGON ((33.90371 -0.95000, 34.07262 -1.05982...
2 603253 Africa W. Sahara ESH 906.5 POLYGON ((-8.66559 27.65643, -8.66512 27.58948...
3 35623680 North America Canada CAN 1674000.0 MULTIPOLYGON (((-122.84000 49.00000, -122.9742...
4 326625791 North America United States of America USA 18560000.0 MULTIPOLYGON (((-122.84000 49.00000, -120.0000...
.. ... ... ... ... ... ...
172 7111024 Europe Serbia SRB 101800.0 POLYGON ((18.82982 45.90887, 18.82984 45.90888...
173 642550 Europe Montenegro MNE 10610.0 POLYGON ((20.07070 42.58863, 19.80161 42.50009...
174 1895250 Europe Kosovo -99 18490.0 POLYGON ((20.59025 41.85541, 20.52295 42.21787...
175 1218208 North America Trinidad and Tobago TTO 43570.0 POLYGON ((-61.68000 10.76000, -61.10500 10.890...
176 13026129 Africa S. Sudan SSD 20880.0 POLYGON ((30.83385 3.50917, 29.95350 4.17370, ...
[177 rows x 6 columns]
Specifically, it's in WGS84 (aka EPSG:4326). The units are degrees:
In [4]: gdf.crs
Out[4]:
<Geographic 2D CRS: EPSG:4326>
Name: WGS 84
Axis Info [ellipsoidal]:
- Lat[north]: Geodetic latitude (degree)
- Lon[east]: Geodetic longitude (degree)
Area of Use:
- name: World.
- bounds: (-180.0, -90.0, 180.0, 90.0)
Datum: World Geodetic System 1984 ensemble
- Ellipsoid: WGS 84
- Prime Meridian: Greenwich
If we call the area property, geopandas will issue a warning, but it will still calculate the area for us. The total area of the earth comes out to 21,497 degrees^2, which roughly 1/3 of 180*360:
In [6]: gdf.area.sum()
<ipython-input-6-10238de14784>:1: UserWarning: Geometry is in a geographic CRS. Results from 'area' are likely incorrect. Use 'GeoSeries.to_crs()' to re-project geometries to a projected CRS before this operation.
gdf.area.sum()
Out[6]: 21496.990987992736
If we instead use an equal area projection, we'll get something much closer to the land area of the earth, in m^2:
In [10]: gdf.to_crs('+proj=cea').area.sum() / 1e3 / 1e3 / 1e6
Out[10]: 147.36326937311017

Related

Geopandas geoseries area - units?

I have a GeoPandas DataFrame. I apply a couple of functions to the GeoDataFrame.
Buffer - https://geopandas.org/en/stable/docs/reference/api/geopandas.GeoSeries.buffer.html
This creates a set of points around the coordinates / geometry.
import geopandas
from shapely.geometry import Point, LineString, Polygon
s = geopandas.GeoSeries(
[
Polygon([(0, 0), (1, 1), (0, 1)]),
Polygon([(10, 0), (10, 5), (0, 0)]),
Polygon([(0, 0), (2, 2), (2, 0)]),
LineString([(0, 0), (1, 1), (0, 1)]),
Point(0, 1)
]
)
s.buffer(0.2)
Now, I'd like to measure the area of the buffered geometry using: https://geopandas.org/en/stable/docs/reference/api/geopandas.GeoSeries.area.html
s.area
The crs info of the DataFrame is:
<Derived Projected CRS: ESRI:102003>
Name: USA_Contiguous_Albers_Equal_Area_Conic
Axis Info [cartesian]:
- E[east]: Easting (metre)
- N[north]: Northing (metre)
Area of Use:
- name: United States (USA) - CONUS onshore - Alabama; Arizona; Arkansas; California; Colorado; Connecticut; Delaware; Florida; Georgia; Idaho; Illinois; Indiana; Iowa; Kansas; Kentucky; Louisiana; Maine; Maryland; Massachusetts; Michigan; Minnesota; Mississippi; Missouri; Montana; Nebraska; Nevada; New Hampshire; New Jersey; New Mexico; New York; North Carolina; North Dakota; Ohio; Oklahoma; Oregon; Pennsylvania; Rhode Island; South Carolina; South Dakota; Tennessee; Texas; Utah; Vermont; Virginia; Washington; West Virginia; Wisconsin; Wyoming.
- bounds: (-124.79, 24.41, -66.91, 49.38)
Coordinate Operation:
- name: USA_Contiguous_Albers_Equal_Area_Conic
- method: Albers Equal Area
Datum: North American Datum 1983
- Ellipsoid: GRS 1980
- Prime Meridian: Greenwich
My question is: what is the units of the area calculated?
The units of area would be metre^2. The units are reported in the CRS.
Presumably, the actual shapefile has very large values (e.g. in the ~1e6 range). See e.g. this question: Interpreting GeoPandas Polygon coordinates

Why is the spatial resolution of image from WorldView 3 like this?

The output of this image from gdalinfo 20141030-wv03.tif is like this:
Driver: GTiff/GeoTIFF
Files: 20141030-wv03.tif
Size is 16484, 15253
Coordinate System is:
GEOGCRS["WGS 84",
DATUM["World Geodetic System 1984",
ELLIPSOID["WGS 84",6378137,298.257223563,
LENGTHUNIT["metre",1]]],
PRIMEM["Greenwich",0,
ANGLEUNIT["degree",0.0174532925199433]],
CS[ellipsoidal,2],
AXIS["geodetic latitude (Lat)",north,
ORDER[1],
ANGLEUNIT["degree",0.0174532925199433]],
AXIS["geodetic longitude (Lon)",east,
ORDER[2],
ANGLEUNIT["degree",0.0174532925199433]],
ID["EPSG",4326]]
Data axis to CRS axis mapping: 2,1
Origin = (113.959353776485997,23.091020758099145)
Pixel Size = (0.000002966620901,-0.000002966620901)
Metadata:
AREA_OR_POINT=Area
DataType=Generic
Image Structure Metadata:
COMPRESSION=LZW
INTERLEAVE=PIXEL
Corner Coordinates:
Upper Left ( 113.9593538, 23.0910208) (113d57'33.67"E, 23d 5'27.67"N)
Lower Left ( 113.9593538, 23.0457709) (113d57'33.67"E, 23d 2'44.78"N)
Upper Right ( 114.0082556, 23.0910208) (114d 0'29.72"E, 23d 5'27.67"N)
Lower Right ( 114.0082556, 23.0457709) (114d 0'29.72"E, 23d 2'44.78"N)
Center ( 113.9838047, 23.0683958) (113d59' 1.70"E, 23d 4' 6.22"N)
Band 1 Block=128x128 Type=Byte, ColorInterp=Red
NoData Value=256
Band 2 Block=128x128 Type=Byte, ColorInterp=Green
NoData Value=256
Band 3 Block=128x128 Type=Byte, ColorInterp=Blue
NoData Value=256
The spatial resolution is (0.000002966620901,-0.000002966620901), how to understand this value?
I also check another image from WorldView 2, ths output is:
Driver: GTiff/GeoTIFF
Files: 20150708.tif
Size is 9984, 10132
Coordinate System is:
PROJCRS["WGS 84 / UTM zone 50N",
BASEGEOGCRS["WGS 84",
DATUM["World Geodetic System 1984",
ELLIPSOID["WGS 84",6378137,298.257223563,
LENGTHUNIT["metre",1]]],
PRIMEM["Greenwich",0,
ANGLEUNIT["degree",0.0174532925199433]],
ID["EPSG",4326]],
CONVERSION["UTM zone 50N",
METHOD["Transverse Mercator",
ID["EPSG",9807]],
PARAMETER["Latitude of natural origin",0,
ANGLEUNIT["degree",0.0174532925199433],
ID["EPSG",8801]],
PARAMETER["Longitude of natural origin",117,
ANGLEUNIT["degree",0.0174532925199433],
ID["EPSG",8802]],
PARAMETER["Scale factor at natural origin",0.9996,
SCALEUNIT["unity",1],
ID["EPSG",8805]],
PARAMETER["False easting",500000,
LENGTHUNIT["metre",1],
ID["EPSG",8806]],
PARAMETER["False northing",0,
LENGTHUNIT["metre",1],
ID["EPSG",8807]]],
CS[Cartesian,2],
AXIS["(E)",east,
ORDER[1],
LENGTHUNIT["metre",1]],
AXIS["(N)",north,
ORDER[2],
LENGTHUNIT["metre",1]],
USAGE[
SCOPE["unknown"],
AREA["World - N hemisphere - 114°E to 120°E - by country"],
BBOX[0,114,84,120]],
ID["EPSG",32650]]
Data axis to CRS axis mapping: 1,2
Origin = (291153.100000000034925,2705938.760000000242144)
Pixel Size = (0.510000000000000,-0.510000000000000)
Metadata:
AREA_OR_POINT=Area
TIFFTAG_XRESOLUTION=1
TIFFTAG_YRESOLUTION=1
Image Structure Metadata:
INTERLEAVE=BAND
Corner Coordinates:
Upper Left ( 291153.100, 2705938.760) (114d56'22.85"E, 24d27'10.88"N)
Lower Left ( 291153.100, 2700771.440) (114d56'25.58"E, 24d24'22.98"N)
Upper Right ( 296244.940, 2705938.760) (114d59'23.60"E, 24d27'13.32"N)
Lower Right ( 296244.940, 2700771.440) (114d59'26.26"E, 24d24'25.41"N)
Center ( 293699.020, 2703355.100) (114d57'54.57"E, 24d25'48.15"N)
Band 1 Block=9984x1 Type=Byte, ColorInterp=Red
Band 2 Block=9984x1 Type=Byte, ColorInterp=Green
Band 3 Block=9984x1 Type=Byte, ColorInterp=Blue
The spatial resolution is (0.510000000000000,-0.510000000000000). How do I understand their difference between them? Thanks.
Your images are in two different coordinate systems.
Your second file 20150708.tif is in an UTM projection (UTM 50N to be exact) which has map units in meters - that's why the pixel resolutions is in meters (0.51m).
Your first file 20141030-wv03.tif is in a geographic coordinate system, the widely used World Geodetic System 1984 (or WGS84) which has map units in degrees, giving you the pixel resolution also in (decimal) degrees. On the equator 0.00001 degrees is around 1.11 meters so both images have likely the same resolution.
For more info on WGS84 vs UTM, this post on GIS stackexchange might be interesting.

How do I insert spatial data into a table contains road column

I am getting this error message while I am trying to insert my data into line table, using coordinates for points between road segments.
ERROR: parse error - invalid geometry
HINT: "SRID=27700;LINESTRING((5" <-- parse error at position 24 within geometry
SQL state: XX000
Part of my code:
NSERT INTO public."RoadSegments"("no", "seg_ID", "description", "location", "length", "the_geom")
VALUES
(1,'Seg_1','Shephards Bush to Royal Crescent','Shephards Bush','540',ST_GeomFromEWKT('SRID=27700;LINESTRING((51.504593 -0.220437),(51.505233 -0.214105))')),
(2,'Seg_2','Royal Crescent to Norland Square','Notting Hill','306',ST_GeomFromEWKT('SRID=27700;LINESTRING((51.505233 -0.214105),(51.506053 -0.209956))')),
(3,'Seg_3','Norland Square to Holland Park','Notting Hill','383',ST_GeomFromEWKT('SRID=27700;LINESTRING((51.506053 -0.209956),(51.507575 -0.204795))')),
(4,'Seg_4','Holland Park to Notting Hill Gate','Notting Hill','477',ST_GeomFromEWKT('SRID=27700;LINESTRING((51.507575 -0.204795),(51
You seem to have too much parentheses in your LINESTRING parameters. Try the following:
INSERT INTO public."RoadSegments"("no", "seg_ID", "description", "location", "length", "the_geom")
VALUES
(1,'Seg_1','Shephards Bush to Royal Crescent', 'Shephards Bush','540',ST_GeomFromEWKT('SRID=27700;LINESTRING(51.504593 -0.220437,51.505233 -0.214105)')),
(2,'Seg_2','Royal Crescent to Norland Square', 'Notting Hill', '306',ST_GeomFromEWKT('SRID=27700;LINESTRING(51.505233 -0.214105,51.506053 -0.209956)')),
(3,'Seg_3','Norland Square to Holland Park', 'Notting Hill', '383',ST_GeomFromEWKT('SRID=27700;LINESTRING(51.506053 -0.209956,51.507575 -0.204795)')),
(4,'Seg_4','Holland Park to Notting Hill Gate','Notting Hill', '477',ST_GeomFromEWKT('SRID=27700;LINESTRING(51.507575 -0.204795,51 ... '))
This should be the correct syntax (no extra parentheses around the coordinates)

Regression estimation in Eviews

I estimate the dependency of export,gdp and human capital. If choosing the linear method, I got this:
Dependent Variable: EXPORTS
Method: Least Squares
Date: 05/23/15 Time: 18:20
Sample: 1960 2011
Included observations: 52
Variable Coefficient Std. Error t-Statistic Prob.
C 2.63E+10 1.38E+10 1.911506 0.0618
HC -1.36E+10 6.08E+09 -2.233089 0.0301
GDP 2903680. 192313.2 15.09870 0.0000
R-squared 0.967407 Mean dependent var 1.90E+10
Adjusted R-squared 0.966076 S.D. dependent var 2.22E+10
S.E. of regression 4.08E+09 Akaike info criterion 47.15324
Sum squared resid 8.16E+20 Schwarz criterion 47.26581
Log likelihood -1222.984 Hannan-Quinn criter. 47.19640
F-statistic 727.1844 Durbin-Watson stat 0.745562
Prob(F-statistic) 0.000000
The sign of HC coefficient is negative, which is against the theory.I have tried logarithmic, exponential forms, but I still get negative results for HC.
I wonder what is the way to estimate it right.
Thank you in advance.
here is my data
Durbin-Watson stat 0.745562
It means that there is auto correlation problem in your model.

NetLogo, how to hatch a turtle at a certain distance on Gis layers

My patches contain attributes such as elevation :
set mnt gis:load-dataset "F:/StageM2/Modelisation/Modele/mnt.asc"
gis:apply-raster mnt alt
gis:set-transformation (list 567887.504252 573503.504252 6183200.86463 6187628.86463) (list min-pxcor max-pxcor min-pycor max-pycor)
gis:set-world-envelope gis:envelope-of mnt
and turtles are created from raster of forest :
to import-foret93
set foret-93 gis:load-dataset "F:/StageM2/Modelisation/Modele/foret76_93.asc"
gis:apply-raster foret-93 f93
ask patches with [f93 = 1]
[
set pcolor black
set foret93? true
;ask n-of 2813 patches with [foret93? = true] [ hatch 2813 ]
sprout-arbres 1 [set color pink
set size 4]
]
end
The layers have the same spatial reference : RGF1993, so it is in meters.
Now, I want to create new turtles from existing turtles and randomly in a radius of 150m from the turtle (the new turtle can be hatch at 1m or at 130m). For instance, I ask just one turtle to hatch a turtle at a distance giving by an input box in the interface named dispersal-dist.
to disp-graines
ask turtle 2918
[
hatch-arbres 1
[
let seedX xcor
let seedY ycor
let ran-bear random 360
lt ran-bear
move-to one-of patches in-radius dispersal-dist
set color magenta
set size 15
]
]
end
But the created turtle go further then the dispersal distance giving in meters.
Did I forget something to transforme the netlogo scale in meters ? Or it is another problem?
Thank you in advance for your help !
While your raster dataset is expressed in meters in your case, your patches don't have a real world scale. Assuming your raster has square pixels, you can calculate a patch scale with something like:
let patch-scale (item 1 gis:world-envelope - item 0 gis:world-envelope ) / world-width
You could then use it in your existing code:
move-to one-of patches in-radius dispersal-dist / patch-scale
If your pixels in your raster have different real world height and width, you will have to do the patch-scale for the horizontal and vertical dimension separately.