geopandas

Relocating legend from GeoPandas plot

天大地大妈咪最大 提交于 2020-01-02 01:16:11
问题 I'm plotting a map with legends using the GeoPandas plotting function. When I plot, my legends appear in the upper right corner of the figure. Here is how it looks like: I wanted to move the legends to the lower part of the graph. I would normally would have done something like this for a normal matplotlib plot: fig, ax = plt.subplots(1, figsize=(4.5,10)) lima_bank_num.plot(ax=ax, column='quant_cuts', cmap='Blues', alpha=1, legend=True) ax.legend(loc='lower left') However, this modification

Change background map for contextily

拜拜、爱过 提交于 2020-01-01 05:26:05
问题 I have this code: import pandas as pd import numpy as np from geopandas import GeoDataFrame import geopandas from shapely.geometry import LineString, Point import matplotlib.pyplot as plt import contextily ''' Do Something''' df = start_stop_df.drop('track', axis=1) crs = {'init': 'epsg:4326'} gdf = GeoDataFrame(df, crs=crs, geometry=geometry) ax = gdf.plot() contextily.add_basemap(ax) ax.set_axis_off() plt.show() Basically, this generates a background map that is in Singapore. However, when

Write GeoDataFrame into SQL Database

牧云@^-^@ 提交于 2019-12-28 18:02:21
问题 I hope that my question is not ridiculous since, surprisingly, this question has apparently not really been asked yet (to the best of my knowledge) on the popular websites. The situation is that I have several csv files containing more than 1 Mio observations in total. Each observation contains, among others, a postal address. I am planning to read all files into a single GeoDataFrame, geocode the addresses, perform a spatial join given a shapefile and save some information from the polygon

Define points within a polygon

风流意气都作罢 提交于 2019-12-26 02:56:08
问题 I have a list of customers lat and long and I want to define which ones are within a given polygon. But the results I got are none of them in that polygon and it is not correct. Could you please help? Thanks! from shapely.geometry import Polygon from shapely.geometry import Point import pandas as pd import geopandas as gpd df=pd.read_csv("C:\\Users\\n.nguyen.2\\Documents\\order from May 1.csv") geometry=[Point(xy) for xy in zip(df['customer_lat'],df['customer_lng'])] crs={'init':'epsg:4326'}

Changing the order of entries for a geopandas choropleth map legend

孤者浪人 提交于 2019-12-24 19:27:17
问题 I am plotting a certain categorical value over the map of a city. The line of code I use to plot is the following: fig = plt.figure(figsize=(12, 12)) ax = plt.gca() urban_data.plot(column="category", cmap="viridis", ax=ax, categorical=True, / k=4, legend=True, linewidth=0.5, / legend_kwds={'fontsize':'19', 'loc':'lower left'}) where urban data is a geopandas dataframe, and I am using matplotlib as plotting library. The argument legend_kwds allows me to control minor things on the legend, like

How to install Contextily?

一曲冷凌霜 提交于 2019-12-24 00:47:06
问题 This question is written in relation with the answer to Plotting a map using geopandas and matplotlib. The main point is that installing (spatial) libraries such as Proj.4 or Contextily can be a confusing task under Windows, so that most of the time we are advised to directly use the OSGeo4W software distribution. An example of such an advise here. A contrario , the task is rather easy with other operating systems. The main idea is to provide interrogative users with a "lite" installation

GeoPandas Set CRS on Points

随声附和 提交于 2019-12-21 07:55:56
问题 Given the following GeoDataFrame: h=pd.DataFrame({'zip':[19152,19047], 'Lat':[40.058841,40.202162], 'Lon':[-75.042164,-74.924594]}) crs='none' geometry = [Point(xy) for xy in zip(h.Lon, h.Lat)] hg = GeoDataFrame(h, crs=crs, geometry=geometry) hg Lat Lon zip geometry 0 40.058841 -75.042164 19152 POINT (-75.042164 40.058841) 1 40.202162 -74.924594 19047 POINT (-74.924594 40.202162) I need to set the CRS as I did with another GeoDataFrame (like this): c=c.to_crs("+init=epsg:3857 +ellps=GRS80

How can I count the number of polygons a shape intersects?

我们两清 提交于 2019-12-18 09:35:07
问题 I have a very large dataset with a polygons and points with buffers around them. I would like to creat a new column in the points data which includes the number of polygons that point's buffer intersects. Heres a simplified example: import pandas as pd import geopandas as gp from shapely.geometry import Polygon from shapely.geometry import Point import matplotlib.pyplot as plt ## Create polygons and points ## df = gp.GeoDataFrame([['a',Polygon([(1, 0), (1, 1), (2,2), (1,2)])], ['b',Polygon([

Polar Stereographic projection of geopandas world map

会有一股神秘感。 提交于 2019-12-14 02:29:38
问题 I want to use the geopandas included low resolution world map (see here) as a background for my data. This works fine as long as I use e.g. 'PlateCarree' projection. If I now want to use a polar stereographic peojection ccrs.NorthPolarStereo() or ccrs.SouthPolarStereo() It does not work. My code looks like this (using python 3) import geopandas as gpd import cartopy.crs as ccrs crs = ccrs.NorthPolarStereo() crs_proj4 = crs.proj4_init world = gpd.read_file(gpd.datasets.get_path("naturalearth

Using Geopandas, how do I select all points not within a polygon?

耗尽温柔 提交于 2019-12-13 14:08:02
问题 I have a DataFrame containing Chicago addresses which I've geocoded into latitude and longitude values, and then into Point objects (making the DataFrame a GeoDataFrame). A small fraction have been incorrectly geocoded with LatLong values outside of Chicago. I have a shapefile for Chicago's boundary (GeoDataFrame), I want to select all rows where the Points are outside of Chicago's boundary polygon. It would be easy to select all points within the polygon (via geopandas sjoin function), but I