Skip to content

Commit 7ec30b7

Browse files
committed
Merge pull request #296 from BibMartin/geopandas
Enable GeoPandas drawing
2 parents 697ef75 + e0de3cb commit 7ec30b7

8 files changed

Lines changed: 412 additions & 1 deletion

File tree

examples/GeoJSON and choropleth.ipynb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -619,6 +619,15 @@
619619
"m"
620620
]
621621
},
622+
{
623+
"cell_type": "markdown",
624+
"metadata": {},
625+
"source": [
626+
"### GeoPandas\n",
627+
"\n",
628+
"Note that you can also create a GeoJson object in using a GeoPandas DataFrame. There's another notebook example for this. "
629+
]
630+
},
622631
{
623632
"cell_type": "markdown",
624633
"metadata": {},

examples/GeoPandas.ipynb

Lines changed: 390 additions & 0 deletions
Large diffs are not rendered by default.

examples/nybb.dbf

537 Bytes
Binary file not shown.

examples/nybb.prj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
PROJCS["NAD_1983_StatePlane_New_York_Long_Island_FIPS_3104_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["Lambert_Conformal_Conic"],PARAMETER["False_Easting",984250.0],PARAMETER["False_Northing",0.0],PARAMETER["Central_Meridian",-74.0],PARAMETER["Standard_Parallel_1",40.66666666666666],PARAMETER["Standard_Parallel_2",41.03333333333333],PARAMETER["Latitude_Of_Origin",40.16666666666666],UNIT["Foot_US",0.3048006096012192]]

examples/nybb.shp

1.16 MB
Binary file not shown.

examples/nybb.shp.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<metadata xml:lang="en"><Esri><CreaDate>20120927</CreaDate><CreaTime>11314100</CreaTime><SyncOnce>FALSE</SyncOnce><SyncDate>20140319</SyncDate><SyncTime>11581800</SyncTime><ModDate>20140319</ModDate><ModTime>11581800</ModTime><DataProperties><itemProps><itemName Sync="TRUE">nybb</itemName><itemLocation><linkage Sync="FALSE">withheld</linkage><protocol Sync="TRUE">Local Area Network</protocol></itemLocation><imsContentType Sync="TRUE">002</imsContentType><nativeExtBox><westBL Sync="TRUE">913174.999355</westBL><eastBL Sync="TRUE">1067382.508606</eastBL><southBL Sync="TRUE">120121.779352</southBL><northBL Sync="TRUE">272844.294006</northBL><exTypeCode Sync="TRUE">1</exTypeCode></nativeExtBox><itemSize Sync="TRUE">0.000</itemSize></itemProps><coordRef><type Sync="TRUE">Projected</type><geogcsn Sync="TRUE">GCS_North_American_1983</geogcsn><csUnits Sync="TRUE">Linear Unit: Foot_US (0.304801)</csUnits><projcsn Sync="TRUE">NAD_1983_StatePlane_New_York_Long_Island_FIPS_3104_Feet</projcsn><peXml Sync="TRUE">&lt;ProjectedCoordinateSystem xsi:type='typens:ProjectedCoordinateSystem' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xs='http://www.w3.org/2001/XMLSchema' xmlns:typens='http://www.esri.com/schemas/ArcGIS/10.1'&gt;&lt;WKT&gt;PROJCS[&amp;quot;NAD_1983_StatePlane_New_York_Long_Island_FIPS_3104_Feet&amp;quot;,GEOGCS[&amp;quot;GCS_North_American_1983&amp;quot;,DATUM[&amp;quot;D_North_American_1983&amp;quot;,SPHEROID[&amp;quot;GRS_1980&amp;quot;,6378137.0,298.257222101]],PRIMEM[&amp;quot;Greenwich&amp;quot;,0.0],UNIT[&amp;quot;Degree&amp;quot;,0.0174532925199433]],PROJECTION[&amp;quot;Lambert_Conformal_Conic&amp;quot;],PARAMETER[&amp;quot;False_Easting&amp;quot;,984250.0],PARAMETER[&amp;quot;False_Northing&amp;quot;,0.0],PARAMETER[&amp;quot;Central_Meridian&amp;quot;,-74.0],PARAMETER[&amp;quot;Standard_Parallel_1&amp;quot;,40.66666666666666],PARAMETER[&amp;quot;Standard_Parallel_2&amp;quot;,41.03333333333333],PARAMETER[&amp;quot;Latitude_Of_Origin&amp;quot;,40.16666666666666],UNIT[&amp;quot;Foot_US&amp;quot;,0.3048006096012192],AUTHORITY[&amp;quot;EPSG&amp;quot;,2263]]&lt;/WKT&gt;&lt;XOrigin&gt;-120039300&lt;/XOrigin&gt;&lt;YOrigin&gt;-96540300&lt;/YOrigin&gt;&lt;XYScale&gt;37212589.015695661&lt;/XYScale&gt;&lt;ZOrigin&gt;-100000&lt;/ZOrigin&gt;&lt;ZScale&gt;10000&lt;/ZScale&gt;&lt;MOrigin&gt;-100000&lt;/MOrigin&gt;&lt;MScale&gt;10000&lt;/MScale&gt;&lt;XYTolerance&gt;0.0032808333333333331&lt;/XYTolerance&gt;&lt;ZTolerance&gt;0.001&lt;/ZTolerance&gt;&lt;MTolerance&gt;0.001&lt;/MTolerance&gt;&lt;HighPrecision&gt;true&lt;/HighPrecision&gt;&lt;WKID&gt;102718&lt;/WKID&gt;&lt;LatestWKID&gt;2263&lt;/LatestWKID&gt;&lt;/ProjectedCoordinateSystem&gt;</peXml></coordRef><lineage><Process ToolSource="c:\program files (x86)\arcgis\desktop10.1\ArcToolbox\Toolboxes\Analysis Tools.tbx\Select" Date="20140319" Time="115818">Select c:\temp\BYTES_GP\Districts.gdb\nybb C:\temp\14A\GIS_OUTPUT\Districts\shp\nybb__Iteration.shp "ObjectID&gt;=0 AND ObjectID&lt;3000"</Process><Process ToolSource="c:\program files (x86)\arcgis\desktop10.1\ArcToolbox\Toolboxes\Analysis Tools.tbx\Select" Date="20140319" Time="115819">Select C:\temp\14A\GIS_OUTPUT\Districts\shp\nybb__Iteration.shp C:\temp\14A\GIS_OUTPUT\Districts\shp\nybb.shp #</Process></lineage></DataProperties><ArcGISFormat>1.0</ArcGISFormat><scaleRange><minScale>150000000</minScale><maxScale>5000</maxScale></scaleRange></Esri><mdLang><languageCode value="eng"/><countryCode value="USA" Sync="TRUE"/></mdLang><mdChar><CharSetCd value="004"/></mdChar><mdHrLv><ScopeCd value="005"/></mdHrLv><mdContact><rpOrgName>New York City Department of City Planning</rpOrgName><rpPosName>BYTES of the BIG APPLE Coordinator</rpPosName><rpCntInfo><cntPhone><voiceNum>212.720.3505</voiceNum></cntPhone><cntAddress addressType="both"><delPoint>22 Reade St, 5E</delPoint><city>New York</city><adminArea>New York</adminArea><postCode>10007</postCode><country>US</country></cntAddress></rpCntInfo><role><RoleCd value="007"/></role></mdContact><distInfo><distributor><distorCont><rpOrgName>New York City Department of City Planning</rpOrgName><rpCntInfo><cntAddress addressType="both"><delPoint>22 Reade St, 5E</delPoint><city>New York</city><adminArea>New York</adminArea><postCode>10007</postCode><country>US</country></cntAddress><cntInstr>Available at the following website: http://www.nyc.gov/html/dcp/html/bytes/applbyte.shtml</cntInstr></rpCntInfo><role><RoleCd value="005"/></role></distorCont><distorOrdPrc><resFees>Free</resFees></distorOrdPrc></distributor><distTranOps><onLineSrc><linkage>http://www.nyc.gov/html/dcp/html/bytes/applbyte.shtml</linkage></onLineSrc><transSize Sync="TRUE">0.000</transSize></distTranOps><distFormat><formatName Sync="FALSE">ESRI Shapefile</formatName><formatVer>Open Specification</formatVer></distFormat></distInfo><dataIdInfo><idCitation><resTitle Sync="FALSE">New York City Borough Boundary</resTitle><resEd>14A</resEd><citRespParty><rpOrgName>New York City Department of City Planning</rpOrgName><role><RoleCd value="010"/></role></citRespParty><citRespParty><rpOrgName>New York City Department of City Planning</rpOrgName><role><RoleCd value="006"/></role></citRespParty><datasetSeries><seriesName>BYTES of the BIG APPLE</seriesName><issId>14A</issId></datasetSeries><otherCitDet>No major changes since previous version.</otherCitDet><date><createDate>2014-03-14T00:00:00</createDate><pubDate>2014-03-31T00:00:00</pubDate></date><presForm><PresFormCd value="005" Sync="TRUE"/></presForm></idCitation><idAbs>&lt;DIV STYLE="text-align:Left;"&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;P&gt;&lt;SPAN&gt;The borough boundaries of New York City clipped to the shoreline at mean high tide.&lt;/SPAN&gt;&lt;/P&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;</idAbs><idPurp>These districts were created by the Department of City Planning to aid city agencies in administering public services.</idPurp><idStatus><ProgCd value="001"/></idStatus><idPoC><rpOrgName>New York City Department of City Planning</rpOrgName><rpPosName>BYTES of the BIG APPLE Coordinator</rpPosName><rpCntInfo><cntPhone><voiceNum>212.720.3505</voiceNum></cntPhone><cntAddress addressType="both"><delPoint>22 Reade St, 5E</delPoint><city>New York</city><adminArea>NY</adminArea><postCode>10007</postCode><country>US</country></cntAddress></rpCntInfo><role><RoleCd value="007"/></role></idPoC><resMaint><maintFreq><MaintFreqCd value="006"/></maintFreq></resMaint><placeKeys><keyword>New York City</keyword><keyword>Brooklyn</keyword><keyword>Bronx</keyword><keyword>Manhattan</keyword><keyword>Kings</keyword><keyword>Staten Island</keyword><keyword>New York</keyword><keyword>Queens</keyword><keyword>Richmond</keyword></placeKeys><themeKeys><keyword>boundaries</keyword><keyword>boundary</keyword><keyword>borough</keyword></themeKeys><searchKeys><keyword>New York City</keyword><keyword>Brooklyn</keyword><keyword>Bronx</keyword><keyword>Manhattan</keyword><keyword>boundaries</keyword><keyword>Kings</keyword><keyword>boundary</keyword><keyword>Staten Island</keyword><keyword>New York</keyword><keyword>Queens</keyword><keyword>borough</keyword><keyword>Richmond</keyword></searchKeys><resConst><LegConsts><othConsts>The data is freely available to all New York City agencies and the public.</othConsts></LegConsts></resConst><resConst><SecConsts><class><ClasscationCd value="001"/></class></SecConsts></resConst><resConst><Consts><useLimit>&lt;DIV STYLE="text-align:Left;"&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;P&gt;&lt;SPAN&gt;This dataset is being provided by the Department of City Planning (DCP) on DCP’s website for informational purposes only. DCP does not warranty the completeness, accuracy, content, or fitness for any particular purpose or use of the dataset, nor are any such warranties to be implied or inferred with respect to the dataset as furnished on the website. DCP and the City are not liable for any deficiencies in the completeness, accuracy, content, or fitness for any particular purpose or use the dataset, or applications utilizing the dataset, provided by any third party.&lt;/SPAN&gt;&lt;/P&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;</useLimit></Consts></resConst><dataLang><languageCode value="eng"/><countryCode value="USA" Sync="TRUE"/></dataLang><dataExt><exDesc>ground condition</exDesc></dataExt><suppInfo>The official borough boundaries include areas under water. Users requiring these boundaries should use nybbwi instead.</suppInfo><idCredit>Department of City Planning.</idCredit><tpCat><TopicCatCd value="003"/></tpCat><envirDesc Sync="TRUE">Microsoft Windows 7 Version 6.1 (Build 7601) Service Pack 1; Esri ArcGIS 10.1.1.3143</envirDesc><spatRpType><SpatRepTypCd value="001" Sync="TRUE"/></spatRpType><dataExt><geoEle><GeoBndBox esriExtentType="search"><exTypeCode Sync="TRUE">1</exTypeCode><westBL Sync="TRUE">-74.257159</westBL><eastBL Sync="TRUE">-73.699215</eastBL><northBL Sync="TRUE">40.915568</northBL><southBL Sync="TRUE">40.495992</southBL></GeoBndBox></geoEle></dataExt></dataIdInfo><mdMaint><maintFreq><MaintFreqCd value="006"/></maintFreq></mdMaint><dqInfo><dqScope><scpLvl><ScopeCd value="005"/></scpLvl></dqScope><report type="DQCompOm"><measDesc>These data are accurate as of the redistricting after the US Census 2010.</measDesc></report><report type="DQAbsExtPosAcc" dimension="horizontal"><measDesc>The District files are created from the same release version of the Department of City Planning LION file. The LION file is spatially aligned with NYCMap aerial photography.</measDesc></report></dqInfo><eainfo Sync="FALSE"><detailed Name="nybb"><enttyp><enttypl Sync="TRUE">nybb</enttypl><enttypt Sync="TRUE">Feature Class</enttypt><enttypc Sync="TRUE">0</enttypc></enttyp><attr><attrlabl Sync="TRUE">FID</attrlabl><attalias Sync="TRUE">FID</attalias><attrtype Sync="TRUE">OID</attrtype><attwidth Sync="TRUE">4</attwidth><atprecis Sync="TRUE">0</atprecis><attscale Sync="TRUE">0</attscale><attrdef Sync="TRUE">Internal feature number.</attrdef><attrdefs Sync="TRUE">Esri</attrdefs><attrdomv><udom Sync="TRUE">Sequential unique whole numbers that are automatically generated.</udom></attrdomv></attr><attr><attrlabl Sync="TRUE">BoroCode</attrlabl><attalias Sync="TRUE">BoroCode</attalias><attrtype Sync="TRUE">SmallInteger</attrtype><attwidth Sync="TRUE">4</attwidth><atprecis Sync="TRUE">4</atprecis><attscale Sync="TRUE">0</attscale><attrdef>Borough Code</attrdef><attrdomv><edom><edomv>1</edomv><edomvd>Manhattan</edomvd></edom><edom><edomv>2</edomv><edomvd>Bronx</edomvd></edom><edom><edomv>3</edomv><edomvd>Brooklyn</edomvd></edom><edom><edomv>4</edomv><edomvd>Queens</edomvd></edom><edom><edomv>5</edomv><edomvd>Staten Island</edomvd></edom></attrdomv></attr><attr><attrlabl Sync="TRUE">BoroName</attrlabl><attalias Sync="TRUE">BoroName</attalias><attrtype Sync="TRUE">String</attrtype><attwidth Sync="TRUE">32</attwidth><atprecis Sync="TRUE">0</atprecis><attscale Sync="TRUE">0</attscale><attrdef>Name of Borough.</attrdef></attr><attr><attrlabl Sync="TRUE">Shape</attrlabl><attalias Sync="TRUE">Shape</attalias><attrtype Sync="TRUE">Geometry</attrtype><attwidth Sync="TRUE">0</attwidth><atprecis Sync="TRUE">0</atprecis><attscale Sync="TRUE">0</attscale><attrdef Sync="TRUE">Feature geometry.</attrdef><attrdefs Sync="TRUE">ESRI</attrdefs><attrdomv><udom Sync="TRUE">Coordinates defining the features.</udom></attrdomv></attr><attr><attrlabl Sync="TRUE">Shape_Leng</attrlabl><attalias Sync="TRUE">Shape_Leng</attalias><attrtype Sync="TRUE">Double</attrtype><attwidth Sync="TRUE">19</attwidth><atprecis Sync="TRUE">0</atprecis><attscale Sync="TRUE">0</attscale></attr><attr><attrlabl Sync="TRUE">Shape_Area</attrlabl><attalias Sync="TRUE">Shape_Area</attalias><attrtype Sync="TRUE">Double</attrtype><attwidth Sync="TRUE">19</attwidth><atprecis Sync="TRUE">0</atprecis><attscale Sync="TRUE">0</attscale><attrdef Sync="TRUE">Area of feature in internal units squared.</attrdef><attrdefs Sync="TRUE">ESRI</attrdefs><attrdomv><udom Sync="TRUE">Positive real numbers that are automatically generated.</udom></attrdomv></attr></detailed></eainfo><mdHrLvName Sync="TRUE">dataset</mdHrLvName><refSysInfo><RefSystem><refSysID><identCode code="2263" Sync="TRUE"/><idCodeSpace Sync="TRUE">EPSG</idCodeSpace><idVersion Sync="TRUE">7.11.2</idVersion></refSysID></RefSystem></refSysInfo><spatRepInfo><VectSpatRep><geometObjs Name="nybb"><geoObjTyp><GeoObjTypCd value="002" Sync="TRUE"></GeoObjTypCd></geoObjTyp><geoObjCnt Sync="TRUE">0</geoObjCnt></geometObjs><topLvl><TopoLevCd value="001" Sync="TRUE"></TopoLevCd></topLvl></VectSpatRep></spatRepInfo><spdoinfo><ptvctinf><esriterm Name="nybb"><efeatyp Sync="TRUE">Simple</efeatyp><efeageom code="4" Sync="TRUE"></efeageom><esritopo Sync="TRUE">FALSE</esritopo><efeacnt Sync="TRUE">0</efeacnt><spindex Sync="TRUE">FALSE</spindex><linrefer Sync="TRUE">FALSE</linrefer></esriterm></ptvctinf></spdoinfo><mdDateSt Sync="TRUE">20140319</mdDateSt></metadata>

examples/nybb.shx

140 Bytes
Binary file not shown.

folium/features.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,8 +238,18 @@ def __init__(self, data, style_function=None):
238238
else: # This is a filename
239239
self.embed = False
240240
self.data = data
241+
elif data.__class__.__name__ in ['GeoDataFrame', 'GeoSeries']:
242+
self.embed = True
243+
if hasattr(data, '__geo_interface__'):
244+
# We have a GeoPandas 0.2 object
245+
self.data = json.loads(json.dumps(data.to_crs(epsg='4326').__geo_interface__))
246+
elif hasattr(data, 'columns'):
247+
# We have a GeoDataFrame 0.1
248+
self.data = json.loads(data.to_crs(epsg='4326').to_json())
249+
else:
250+
raise ValueError('Unable to transform this object to a GeoJSON.')
241251
else:
242-
raise ValueError('Unhandled data type.')
252+
raise ValueError('Unhandled object {!r}.'.format(data))
243253

244254
if style_function is None:
245255
style_function = lambda x: {}

0 commit comments

Comments
 (0)