contextily | Context geo-tiles in Python | Map library
kandi X-RAY | contextily Summary
kandi X-RAY | contextily Summary
contextily is a small Python 3 (3.7 and above) package to retrieve tile maps from the internet. It can add those tiles as basemap to matplotlib figures or write tile maps to disk into geospatial raster files. Bounding boxes can be passed in both WGS84 (EPSG:4326) and Spheric Mercator (EPSG:3857). See the notebook contextily_guide.ipynb for usage.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of contextily
contextily Key Features
contextily Examples and Code Snippets
Community Discussions
Trending Discussions on contextily
QUESTION
I'm trying to plot a trip on the map of France but I can't plot only the map of France (see image), could someone help me with this ? I believe this may be an issue with the crs from the contextily library but I didn't find any information on the web Here is a reproducible example...
...ANSWER
Answered 2022-Jan-05 at 09:57Two points
- France is a MutliPolygon, where part is in Antartica. Have excluded this from geometry
- need to be very consistent with CRS. Additionally best not to use legacy for of referencing CRS
{"init": "epsg:4326"}
QUESTION
I'm doing a jointplot with a basemap, the problem is that when I add the basemap the main plot doesn't have the same size of the marginal plots. I've tried with different parameters without luck. Does anyone have an idea?
...ANSWER
Answered 2021-Dec-11 at 00:14Here is an approach that:
- removes the axes sharing in the y-direction to be able to change the aspect to
'datalim'
- sets the aspect to
'equal', 'datalim'
- sets the y data limits of the marginal plot to be the same as the joint plot; this seems to need a redraw
The following code shows the idea (using imshow
, as I don't have contextily
installed):
QUESTION
Using the matplotlib
backend, is it possible to add a tile basemap such as OSM to a GeoViews
plot, e.g. by somehow calling contextily
? Using the Bokeh
backend, this is done via gv.tile_sources
and then adding it to an overlay but is there a similar function for the mpl
backend?
Adding a reproducible example assuming one is switching between backends, and using neighbourhood-level polygon gdfs in EPSG:4326.
What made me initially think adding a basemap was not possible was (1) not defining the WMTS zoom level (causing undecipherable pixelated text to be plotted instead of features), and, after reading James' answer, (2) adding the tiles layer to the layout last, not first, which caused tiles to cover the polygons layers (not an issue on the bokeh backend, but with matplotlib apparently it does matter).
...ANSWER
Answered 2021-Aug-01 at 16:58QUESTION
I have a dataframe of individual addresses with lat/long that I converted to a GeoPandas dataframe. I set the projection to the Contextily EPSG:3857 projection.
...ANSWER
Answered 2021-May-05 at 09:29The CRS of your geometries is not 3857 but 4326. Coordinates are clearly in degrees.
QUESTION
I'm trying to plot a set of points on a basemap using contextily in python. I have the following points object generated by shapely.geometry, long first and then lat.
0 POINT (-122.44040676 37.7452892821)
1 POINT (-122.432337016 37.7814273807)
2 POINT (-122.409302275 37.7923551768)
3 POINT (-122.446989285 37.7963790178)
4 POINT (-122.412922159 37.8076612624)
I then converted it into a geopandas data and used to following to plot it.
...ANSWER
Answered 2021-Jan-16 at 10:10Assuming your geoDataFrame is created with a valid crs
, when you add_basemap
the crs
can be specified with option crs=gdf.crs.to_string()
to reproject the map images properly. Here is the relevant line of code that needs to change.
QUESTION
Using Python 3.8, GeoPandas, and Contextily, I am plotting a lot of maps in different areas at different zoom levels (looping through list of points in a GeoDataFrame). Different zoom levels work for different global areas.
What is the best way to set the zoom to the max allowable, capturing the points that I am plotting? In the code below, I don't know how to:
- Return max zoom allowable (I just used 13 in second plot because that was in error message)
- Change the extents in the second plot-- the extents of the second plot are the same as the first; I would have expected that changing the zoom level would change the extents
I think I have correctly set the EPSG, which was the gist of the answer to a similar question here.
Code:
...ANSWER
Answered 2021-Jan-17 at 06:19As it is confirmed by the asker. Adding option reset_extent=False
to ctx.add_basemap(ax2, ... )
will solve the problem of plotting on ax2
.
For checking a possible zoom value before actually using it. Use this
QUESTION
I have a point geometry of US locations contained in a GeoDataFrame. I want to plot this as a scatterplot over the US map. My code is:
...ANSWER
Answered 2021-Jan-15 at 07:18The plot looks good. I guess you want to exclude the points outside conterminous USA. Those points are clearly in Hawaii, Alaska, and Canada.
From your geodataframe with point
geometry, gdf, and with polygon
geometry, boundary, you can create a proper boundary that can be used to limit the scatter of the points.
QUESTION
I am trying to add a real map behind my plot in order to show the locations of my datapoints.
But I don't know how to add the real map...
I've tried several ways, like put another png behind the plot.
But it just not right.
Here is what I got.
...ANSWER
Answered 2020-Dec-02 at 16:53Use contextily
library made for GeoPandas. - https://contextily.readthedocs.io/en/latest/
QUESTION
I'm trying to add a contextily basemap to a Matplotlib figure containing a GeoPandas data frame. When I just plot the data frame using df.plot
the map extent is calculated correctly.
However, when I try adding a contextily basemap the map extent (and zoom level) is calculated wrongly and the following warning is shown:
...ANSWER
Answered 2020-Nov-10 at 08:16The GML file of Linz is based on Gauss-Krüger system M31-5Mio (EPSG:31255). Here is runnable code that demonstrates all the steps to produce a plot of the GML with basemap requested from webmap tiles' provider of choice.
QUESTION
Please forgive me as this is my first go at a Python 'Project'.
A quick overview: I am trying to produce maps (MatPlotLib figures) by iterating through a GeoPandas dataframe of a GeoJSON file containing the boundaries of active subdivision phases in order to show the progress of construction of the individual lots in each subdivision phase. We normally did this manually in GIS, but I figured I'd take a stab at automating some, or all, of the process. I am also attempting to do this without using ESRI's python functionality and would prefer to keep it that way for stability for future use as ESRI can move around quite a bit.
I am able to iterate through the geodataframe and produce a map (figure) that is zoomed to the extent of the subdivision phase boundary, however, it is clipping the background aerial imagery basemap to the minimum binding box of the subdivision phase that I have been using to set the 'zoom' of the figure.
Example of what I am aiming to produce. This was made in ArcGIS Pro:
What I am able to make in Python:
I am unable to get the basemap to be a constant size that fills a standard landscape letter page whilst still being correctly zoomed in to the extent of the subdivision phase. My output jpeg is sized correctly, but the aerial imagery basemap is continuously croppped to the extent of the subdivision phase boundary leaving large borders around the figure.
...ANSWER
Answered 2020-Oct-19 at 17:59If you want to have a fixed area which, say, extends the bounding box by 10m, you have to set xlim
and ylim
extended. You are explicitly specifying both to bounding box.
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install contextily
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page