Retrieve polygon label from shape file based on latitude and longitude - python

I am new to working with geospatial data in Python, and I need some help with what I hope is a simple task.
I have a shape file of New York City Police Precincts, which can be found here, and I have a dataframe with two columns, ‘Latitude’ and ‘Longitude’, that are associated with NYC 311 call incident locations. Unfortunately, 311 data does not contain a Police Precinct column, so I am hoping to add that feature myself.
I believe I need to retrieve the polygon label (i.e. ‘5th Precinct’ - or however it phrased) for a given Lat,Long coordinate.
Any help would be greatly appreciated.

Related

Open source data of the world map that includes longitude and latitude information along with land and sea indicator

I've came across OpenStreetMap and it's too large with unnecessary data for my use case.
What I'm searching for is an exact replica of the world map tagged with longitude and latitude information along with an indicator showing whether it's a land or sea, with clear contours of land. I need to be able to draw objects on it and plot it using scripting language like Python. Longitude and latitude information are required for objects I'm plotting and clear contours of land to verify that my plot overlayed above my region of interest.
https://simplemaps.com/data/world-cities provides coordinates of countries and its cities but it'd be better to know how large each country is, hence the requirement of land contours. Any other representation of data is acceptable as long as it is able to indicate that there's land.
you might want to have a look at the NaturalEarth datasets...
https://www.naturalearthdata.com/downloads/
They provide land and ocean shapefiles (and much more) which should fit your purpose.

How to use Spatial Smoothing on relativities at postcode level in Python

I'm after some help with how I can use Spatial smoothing on my data which I have attached.
What I'd like is for neighboring postcodes to not have such a large difference in relativities.
Just to provide little more about these relativities - they are used in calculating the premium charged to a customer for home insurance.
I also have a postcode file which contains for all postcodes in the UK their longitude and latitude coordinates.
Please see attached a small subsection of my data for your reference.

Removing duplicate labels within a given radius

I have 500.000 data of house number (address) with longitude and latitude in a particular area, but I don't want there is the same house number within a 50m radius. Do you know how to detect the existence of the same adjacent numbers within a 50m radius?
is there any method in python, PostGIS, ArcGIS, QGIS, or another spatial tool to solve this?
Thank you.

How to broaden coordinates from a location query?

I have an application where the user can enter a location query such as :
Corinth
The application will add a postfix ",Greece" and calculate the latitude and longitude coordinates for the city. So, the query for the coordinates will be Corinth, Greece.
After, that the application returns the weather forecast for that location using DarkSkyApi. I want to only return forecasts for my country, which is Greece.
The problem is that if a user types : London. Then, the location will return the coordinates of some obscure location in Greece (eg. a cafe) and give a forecast for that location. I think this creates confusion, because it gives the impression of a bug and that the app can predict forecasts for other countries as well.
On the one hand, I want it to be specific enough to work for cities (eg. Athens), villages & neighborhoods (eg. Acropolis). On the other, not for minor locations (eg. cafes).
How can I go about fixing that? If somebody gives a very minor location or foreign city, I would like it to default to the capital city 'Athens', or somehow "broaden" the coordinates to the nearest city. Is there a way, to limit the coordinates somehow or filter the locations ? Is there a way to determine whether the coordinates are for a minor or large location ?

How to determine the projection or coordinate reference system given spatial points

I am just a starter to Spatial Analysis and am stuck at a point.
I have a crime data set where the points are given in latitude and longitude. I have another dataset (a shape file of Chicago) and I would like to plot all the lat-long points on top of map plot using the polygons from the shape file.
The problem is that the shape file contains polygon information in a different format which I am unaware of. I retrieve the shape file from
https://data.cityofchicago.org/Facilities-Geographic-Boundaries/Boundaries-Neighborhoods/9wp7-iasj
From the above download I use the Neighborhoods_2012b.shp file
Latitude Longitude from crime data:
POINT (-87.680162979 41.998718085)
POINT (-87.746717696 41.934629749)
Polygon shapes in the Chicago Shapefile: (All are positive values)
POLYGON ((1182322.0429 1876674.730700001, 1182...
POLYGON ((1176452.803199999 1897600.927599996,...
I tried transforming the Latitude and Longitude information into different projection (Mercator) such as (epsg:3857, epsg:3395), but these projection give me both positive and Negative values
epsg:3857:
POINT (-9760511.095493518 5160787.421333898)
POINT (-9767919.932699846 5151192.321624438)
I even tried transforming all Lat-Long into UTM (using the python UTM library), which hopefully gives me all positive value but still it doesn't seem the right format as the plots are at very different scale.
Using UTM python Library (utm.from_latlon)
POINT (4649857.621612935 443669.2483944244)
POINT (4642787.870839979 438095.1726599361)
I am not sure how to handle this situation, Is there a way to know what type of projection is used given the spatial points?
I'd be glad for any help.
The prj file says:
PROJCS["NAD_1983_StatePlane_Illinois_East_FIPS_1201_Feet",GEOGCS["GCS_North_American_1983",DATUM["D_North_American_1983",SPHEROID["GRS_1980",6378137.0,298.257222101]],PRIMEM["Greenwich",0.0],UNIT["Degree",0.0174532925199433]],PROJECTION["Transverse_Mercator"],PARAMETER["False_Easting",984250.0],PARAMETER["False_Northing",0.0],PARAMETER["Central_Meridian",-88.33333333333333],PARAMETER["Scale_Factor",0.999975],PARAMETER["Latitude_Of_Origin",36.66666666666666],UNIT["Foot_US",0.3048006096012192]]
I opened the layer with QGIS and it did not use the prj file directly. However, with the information of the prj file, you can use the CRS selector to retrieve it. Search parameters are : NAD83 Illinois East here. Choose the one that is in Feet as suggested by the prj file. EPSG = 6455 is a good one for instance. I think you now have enough information to continue...

Categories