mirror of
https://github.com/wassname/geopandas.git
synced 2026-09-11 12:10:59 +08:00
290 lines
18 KiB
HTML
290 lines
18 KiB
HTML
|
|
|
|
<!DOCTYPE html>
|
|
<!--[if IE 8]><html class="no-js lt-ie9" lang="en" > <![endif]-->
|
|
<!--[if gt IE 8]><!--> <html class="no-js" lang="en" > <!--<![endif]-->
|
|
<head>
|
|
<meta charset="utf-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
|
|
<title>Managing Projections — GeoPandas 0.2-py3.5.egg documentation</title>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<link href='https://fonts.googleapis.com/css?family=Lato:400,700,400italic,700italic|Roboto+Slab:400,700|Inconsolata:400,700&subset=latin,cyrillic' rel='stylesheet' type='text/css'>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<link rel="stylesheet" href="_static/css/theme.css" type="text/css" />
|
|
|
|
|
|
|
|
|
|
|
|
<link rel="author" title="About these documents"
|
|
href="about.html"/>
|
|
<link rel="top" title="GeoPandas 0.2-py3.5.egg documentation" href="index.html"/>
|
|
<link rel="next" title="Geometric Manipulations" href="geometric_manipulations.html"/>
|
|
<link rel="prev" title="Mapping Tools" href="mapping.html"/>
|
|
|
|
|
|
<script src="https://cdnjs.cloudflare.com/ajax/libs/modernizr/2.6.2/modernizr.min.js"></script>
|
|
|
|
</head>
|
|
|
|
<body class="wy-body-for-nav" role="document">
|
|
|
|
<div class="wy-grid-for-nav">
|
|
|
|
|
|
<nav data-toggle="wy-nav-shift" class="wy-nav-side">
|
|
<div class="wy-side-nav-search">
|
|
|
|
<a href="index.html" class="fa fa-home"> GeoPandas</a>
|
|
|
|
|
|
<div role="search">
|
|
<form id="rtd-search-form" class="wy-form" action="search.html" method="get">
|
|
<input type="text" name="q" placeholder="Search docs" />
|
|
<input type="hidden" name="check_keywords" value="yes" />
|
|
<input type="hidden" name="area" value="default" />
|
|
</form>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation">
|
|
|
|
|
|
|
|
<ul class="current">
|
|
<li class="toctree-l1"><a class="reference internal" href="install.html">Installation</a><ul>
|
|
<li class="toctree-l2"><a class="reference internal" href="install.html#installing-geopandas">Installing GeoPandas</a></li>
|
|
<li class="toctree-l2"><a class="reference internal" href="install.html#dependencies">Dependencies</a></li>
|
|
</ul>
|
|
</li>
|
|
<li class="toctree-l1"><a class="reference internal" href="data_structures.html">Data Structures</a><ul>
|
|
<li class="toctree-l2"><a class="reference internal" href="data_structures.html#geoseries">GeoSeries</a></li>
|
|
<li class="toctree-l2"><a class="reference internal" href="data_structures.html#geodataframe">GeoDataFrame</a></li>
|
|
</ul>
|
|
</li>
|
|
<li class="toctree-l1"><a class="reference internal" href="io.html">Reading and Writing Files</a><ul>
|
|
<li class="toctree-l2"><a class="reference internal" href="io.html#reading-spatial-data">Reading Spatial Data</a></li>
|
|
<li class="toctree-l2"><a class="reference internal" href="io.html#writing-spatial-data">Writing Spatial Data</a></li>
|
|
</ul>
|
|
</li>
|
|
<li class="toctree-l1"><a class="reference internal" href="mapping.html">Making Maps</a><ul>
|
|
<li class="toctree-l2"><a class="reference internal" href="mapping.html#chloropleth-maps">Chloropleth Maps</a></li>
|
|
<li class="toctree-l2"><a class="reference internal" href="mapping.html#maps-with-layers">Maps with Layers</a></li>
|
|
<li class="toctree-l2"><a class="reference internal" href="mapping.html#other-resources">Other Resources</a></li>
|
|
</ul>
|
|
</li>
|
|
<li class="toctree-l1 current"><a class="current reference internal" href="">Managing Projections</a><ul>
|
|
<li class="toctree-l2"><a class="reference internal" href="#coordinate-reference-systems">Coordinate Reference Systems</a></li>
|
|
<li class="toctree-l2"><a class="reference internal" href="#setting-a-projection">Setting a Projection</a></li>
|
|
<li class="toctree-l2"><a class="reference internal" href="#re-projecting">Re-Projecting</a></li>
|
|
</ul>
|
|
</li>
|
|
<li class="toctree-l1"><a class="reference internal" href="geometric_manipulations.html">Geometric Manipulations</a><ul>
|
|
<li class="toctree-l2"><a class="reference internal" href="geometric_manipulations.html#constructive-methods">Constructive Methods</a></li>
|
|
<li class="toctree-l2"><a class="reference internal" href="geometric_manipulations.html#affine-transformations">Affine transformations</a></li>
|
|
</ul>
|
|
</li>
|
|
<li class="toctree-l1"><a class="reference internal" href="set_operations.html">Set Operations with overlay</a><ul>
|
|
<li class="toctree-l2"><a class="reference internal" href="set_operations.html#the-different-overlay-operations">The different Overlay operations</a></li>
|
|
<li class="toctree-l2"><a class="reference internal" href="set_operations.html#overlay-countries-example">Overlay Countries Example</a></li>
|
|
<li class="toctree-l2"><a class="reference internal" href="set_operations.html#more-examples">More Examples</a></li>
|
|
</ul>
|
|
</li>
|
|
<li class="toctree-l1"><a class="reference internal" href="aggregation_with_dissolve.html">Aggregation with dissolve</a><ul>
|
|
<li class="toctree-l2"><a class="reference internal" href="aggregation_with_dissolve.html#dissolve-example"><code class="docutils literal"><span class="pre">dissolve</span></code> Example</a></li>
|
|
</ul>
|
|
</li>
|
|
<li class="toctree-l1"><a class="reference internal" href="mergingdata.html">Merging Data</a><ul>
|
|
<li class="toctree-l2"><a class="reference internal" href="mergingdata.html#attribute-joins">Attribute Joins</a></li>
|
|
<li class="toctree-l2"><a class="reference internal" href="mergingdata.html#spatial-joins">Spatial Joins</a></li>
|
|
</ul>
|
|
</li>
|
|
<li class="toctree-l1"><a class="reference internal" href="geocoding.html">Geocoding</a></li>
|
|
<li class="toctree-l1"><a class="reference internal" href="reference.html">Reference to All Attributes and Methods</a><ul>
|
|
<li class="toctree-l2"><a class="reference internal" href="reference.html#geodataframe">GeoDataFrame</a></li>
|
|
</ul>
|
|
</li>
|
|
<li class="toctree-l1"><a class="reference internal" href="contributing.html">Contributing to GeoPandas</a><ul>
|
|
<li class="toctree-l2"><a class="reference internal" href="contributing.html#overview">Overview</a></li>
|
|
<li class="toctree-l2"><a class="reference internal" href="contributing.html#forking-the-geopandas-repository-using-git">1) Forking the <em>geopandas</em> repository using Git</a></li>
|
|
<li class="toctree-l2"><a class="reference internal" href="contributing.html#creating-a-development-environment">2) Creating a development environment</a></li>
|
|
<li class="toctree-l2"><a class="reference internal" href="contributing.html#installing-dependencies">3) Installing Dependencies</a></li>
|
|
<li class="toctree-l2"><a class="reference internal" href="contributing.html#making-a-development-build">4) Making a development build</a></li>
|
|
<li class="toctree-l2"><a class="reference internal" href="contributing.html#making-changes-and-writing-tests">5) Making changes and writing tests</a></li>
|
|
<li class="toctree-l2"><a class="reference internal" href="contributing.html#updating-the-documentation">6) Updating the Documentation</a></li>
|
|
<li class="toctree-l2"><a class="reference internal" href="contributing.html#submitting-a-pull-request">7) Submitting a Pull Request</a></li>
|
|
</ul>
|
|
</li>
|
|
<li class="toctree-l1"><a class="reference internal" href="about.html">About</a><ul>
|
|
<li class="toctree-l2"><a class="reference internal" href="about.html#known-issues">Known issues</a></li>
|
|
</ul>
|
|
</li>
|
|
</ul>
|
|
|
|
|
|
|
|
</div>
|
|
|
|
</nav>
|
|
|
|
<section data-toggle="wy-nav-shift" class="wy-nav-content-wrap">
|
|
|
|
|
|
<nav class="wy-nav-top" role="navigation" aria-label="top navigation">
|
|
<i data-toggle="wy-nav-top" class="fa fa-bars"></i>
|
|
<a href="index.html">GeoPandas</a>
|
|
</nav>
|
|
|
|
|
|
|
|
<div class="wy-nav-content">
|
|
<div class="rst-content">
|
|
<div role="navigation" aria-label="breadcrumbs navigation">
|
|
<ul class="wy-breadcrumbs">
|
|
<li><a href="index.html">Docs</a> »</li>
|
|
|
|
<li>Managing Projections</li>
|
|
<li class="wy-breadcrumbs-aside">
|
|
|
|
<a href="_sources/projections.txt" rel="nofollow"> View page source</a>
|
|
|
|
</li>
|
|
</ul>
|
|
<hr/>
|
|
</div>
|
|
<div role="main" class="document">
|
|
|
|
<div class="section" id="managing-projections">
|
|
<h1>Managing Projections<a class="headerlink" href="#managing-projections" title="Permalink to this headline">¶</a></h1>
|
|
<div class="section" id="coordinate-reference-systems">
|
|
<h2>Coordinate Reference Systems<a class="headerlink" href="#coordinate-reference-systems" title="Permalink to this headline">¶</a></h2>
|
|
<p>CRS are important because the geometric shapes in a GeoSeries or GeoDataFrame object are simply a collection of coordinates in an arbitrary space. A CRS tells Python how those coordinates related to places on the Earth.</p>
|
|
<p>CRS are referred to using codes called <a class="reference external" href="https://en.wikipedia.org/wiki/PROJ.4">proj4 strings</a>. You can find the codes for most commonly used projections from <a class="reference external" href="http://spatialreference.org/">www.spatialreference.org</a> or <a class="reference external" href="http://www.remotesensing.org/geotiff/proj_list/">remotesensing.org</a>.</p>
|
|
<p>The same CRS can often be referred to in many ways. For example, one of the most commonly used CRS is the WGS84 latitude-longitude projection. One <cite>proj4</cite> representation of this projection is: <code class="docutils literal"><span class="pre">"+proj=longlat</span> <span class="pre">+ellps=WGS84</span> <span class="pre">+datum=WGS84</span> <span class="pre">+no_defs"</span></code>. But common projections can also be referred to by <cite>EPSG</cite> codes, so this same projection can also called using the <cite>proj4</cite> string <code class="docutils literal"><span class="pre">"+init=epsg:4326"</span></code>.</p>
|
|
<p><em>geopandas</em> can accept lots of representations of CRS, including the <cite>proj4</cite> string itself (<code class="docutils literal"><span class="pre">"+proj=longlat</span> <span class="pre">+ellps=WGS84</span> <span class="pre">+datum=WGS84</span> <span class="pre">+no_defs"</span></code>) or parameters broken out in a dictionary: <code class="docutils literal"><span class="pre">{'proj':</span> <span class="pre">'latlong',</span> <span class="pre">'ellps':</span> <span class="pre">'WGS84',</span> <span class="pre">'datum':</span> <span class="pre">'WGS84',</span> <span class="pre">'no_defs':</span> <span class="pre">True}</span></code>). In addition, some functions will take <cite>EPSG</cite> codes directly.</p>
|
|
<p>For reference, a few very common projections and their proj4 strings:</p>
|
|
<ul class="simple">
|
|
<li>WGS84 Latitude/Longitude: <code class="docutils literal"><span class="pre">"+proj=longlat</span> <span class="pre">+ellps=WGS84</span> <span class="pre">+datum=WGS84</span> <span class="pre">+no_defs"</span></code> or <code class="docutils literal"><span class="pre">"+init=epsg:4326"</span></code></li>
|
|
<li>UTM Zones (North): <code class="docutils literal"><span class="pre">"+proj=utm</span> <span class="pre">+zone=33</span> <span class="pre">+ellps=WGS84</span> <span class="pre">+datum=WGS84</span> <span class="pre">+units=m</span> <span class="pre">+no_defs"</span></code></li>
|
|
<li>UTM Zones (South): <code class="docutils literal"><span class="pre">"+proj=utm</span> <span class="pre">+zone=33</span> <span class="pre">+ellps=WGS84</span> <span class="pre">+datum=WGS84</span> <span class="pre">+units=m</span> <span class="pre">+no_defs</span> <span class="pre">+south"</span></code></li>
|
|
</ul>
|
|
</div>
|
|
<div class="section" id="setting-a-projection">
|
|
<h2>Setting a Projection<a class="headerlink" href="#setting-a-projection" title="Permalink to this headline">¶</a></h2>
|
|
<p>There are two relevant operations for projections: setting a projection and re-projecting.</p>
|
|
<p>Setting a projection may be necessary when for some reason <em>geopandas</em> has coordinate data (x-y values), but no information about how those coordinates refer to locations in the real world. Setting a projection is how one tells <em>geopandas</em> how to interpret coordinates. If no CRS is set, <em>geopandas</em> geometry operations will still work, but coordinate transformations will not be possible and exported files may not be interpreted correctly by other software.</p>
|
|
<p>Be aware that <strong>most of the time</strong> you don’t have to set a projection. Data loaded from a reputable source (using the <code class="docutils literal"><span class="pre">from_file()</span></code> command) <em>should</em> always include projection information. You can see an objects current CRS through the <code class="docutils literal"><span class="pre">crs</span></code> attribute: <code class="docutils literal"><span class="pre">my_geoseries.crs</span></code>.</p>
|
|
<p>From time to time, however, you may get data that does not include a projection. In this situation, you have to set the CRS so <em>geopandas</em> knows how to interpret the coordinates.</p>
|
|
<p>For example, if you convert a spreadsheet of latitudes and longitudes into a GeoSeries by hand, you would set the projection by assigning the WGS84 latitude-longitude CRS to the <code class="docutils literal"><span class="pre">crs</span></code> attribute:</p>
|
|
<div class="highlight-python"><div class="highlight"><pre><span class="n">my_geoseries</span><span class="o">.</span><span class="n">crs</span> <span class="o">=</span> <span class="p">{</span><span class="s">'init'</span> <span class="p">:</span><span class="s">'epsg:4326'</span><span class="p">}</span>
|
|
</pre></div>
|
|
</div>
|
|
</div>
|
|
<div class="section" id="re-projecting">
|
|
<h2>Re-Projecting<a class="headerlink" href="#re-projecting" title="Permalink to this headline">¶</a></h2>
|
|
<p>Re-projecting is the process of changing the representation of locations from one coordinate system to another. All projections of locations on the Earth into a two-dimensional plane <a class="reference external" href="https://en.wikipedia.org/wiki/Map_projection#Which_projection_is_best.3F">are distortions</a>, the projection that is best for your application may be different from the projection associated with the data you import. In these cases, data can be re-projected using the <code class="docutils literal"><span class="pre">to_crs</span></code> command:</p>
|
|
<div class="highlight-ipython"><div class="highlight"><pre><span class="go"># load example data</span>
|
|
<span class="gp">In [1]: </span><span class="n">world</span> <span class="o">=</span> <span class="n">gpd</span><span class="o">.</span><span class="n">read_file</span><span class="p">(</span><span class="n">gpd</span><span class="o">.</span><span class="n">datasets</span><span class="o">.</span><span class="n">get_path</span><span class="p">(</span><span class="s">'naturalearth_lowres'</span><span class="p">))</span>
|
|
|
|
<span class="go"># Check original projection</span>
|
|
<span class="go"># (it's Platte Carre! x-y are long and lat)</span>
|
|
<span class="gp">In [2]: </span><span class="n">world</span><span class="o">.</span><span class="n">crs</span>
|
|
<span class="gh">Out[2]: </span><span class="go">{'init': 'epsg:4326'}</span>
|
|
|
|
<span class="go"># Visualize</span>
|
|
<span class="gp">In [3]: </span><span class="n">world</span><span class="o">.</span><span class="n">plot</span><span class="p">();</span>
|
|
|
|
<span class="go"># Reproject to Mercator (after dropping Antartica)</span>
|
|
<span class="gp">In [4]: </span><span class="n">world</span> <span class="o">=</span> <span class="n">world</span><span class="p">[(</span><span class="n">world</span><span class="o">.</span><span class="n">name</span> <span class="o">!=</span> <span class="s">"Antarctica"</span><span class="p">)</span> <span class="o">&</span> <span class="p">(</span><span class="n">world</span><span class="o">.</span><span class="n">name</span> <span class="o">!=</span> <span class="s">"Fr. S. Antarctic Lands"</span><span class="p">)]</span>
|
|
|
|
<span class="gp">In [5]: </span><span class="n">world</span> <span class="o">=</span> <span class="n">world</span><span class="o">.</span><span class="n">to_crs</span><span class="p">({</span><span class="s">'init'</span><span class="p">:</span> <span class="s">'epsg:3395'</span><span class="p">})</span> <span class="c"># world.to_crs(epsg=3395) would also work</span>
|
|
|
|
<span class="gp">In [6]: </span><span class="n">world</span><span class="o">.</span><span class="n">plot</span><span class="p">();</span>
|
|
</pre></div>
|
|
</div>
|
|
<a class="reference internal image-reference" href="_images/world_starting.png"><img alt="_images/world_starting.png" src="_images/world_starting.png" style="width: 3in;" /></a>
|
|
<a class="reference internal image-reference" href="_images/world_reproj.png"><img alt="_images/world_reproj.png" src="_images/world_reproj.png" style="width: 3in;" /></a>
|
|
</div>
|
|
</div>
|
|
|
|
|
|
</div>
|
|
<footer>
|
|
|
|
<div class="rst-footer-buttons" role="navigation" aria-label="footer navigation">
|
|
|
|
<a href="geometric_manipulations.html" class="btn btn-neutral float-right" title="Geometric Manipulations">Next <span class="fa fa-arrow-circle-right"></span></a>
|
|
|
|
|
|
<a href="mapping.html" class="btn btn-neutral" title="Mapping Tools"><span class="fa fa-arrow-circle-left"></span> Previous</a>
|
|
|
|
</div>
|
|
|
|
|
|
<hr/>
|
|
|
|
<div role="contentinfo">
|
|
<p>
|
|
© Copyright 2013-2016, GeoPandas developers.
|
|
</p>
|
|
</div>
|
|
|
|
Built with <a href="http://sphinx-doc.org/">Sphinx</a> using a <a href="https://github.com/snide/sphinx_rtd_theme">theme</a> provided by <a href="https://readthedocs.org">Read the Docs</a>.
|
|
|
|
</footer>
|
|
</div>
|
|
</div>
|
|
|
|
</section>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
<script type="text/javascript">
|
|
var DOCUMENTATION_OPTIONS = {
|
|
URL_ROOT:'./',
|
|
VERSION:'0.2-py3.5.egg',
|
|
COLLAPSE_INDEX:false,
|
|
FILE_SUFFIX:'.html',
|
|
HAS_SOURCE: true
|
|
};
|
|
</script>
|
|
<script type="text/javascript" src="_static/jquery.js"></script>
|
|
<script type="text/javascript" src="_static/underscore.js"></script>
|
|
<script type="text/javascript" src="_static/doctools.js"></script>
|
|
|
|
|
|
|
|
|
|
|
|
<script type="text/javascript" src="_static/js/theme.js"></script>
|
|
|
|
|
|
|
|
|
|
<script type="text/javascript">
|
|
jQuery(function () {
|
|
SphinxRtdTheme.StickyNav.enable();
|
|
});
|
|
</script>
|
|
|
|
|
|
</body>
|
|
</html> |