GeoPandas: First Map

This notebook introduces geopandas libraray and geospatial analysis

Import Public Packages

import geopandas as gpd
import sys
import os
import pathlib
gpd.__version__
'0.14.4'

Import Private Packages

is_kaggle = 'kaggle_secrets' in sys.modules
if is_kaggle:
    from kaggle_secrets import UserSecretsClient
    user_secrets = UserSecretsClient()
    os.environ['KAGGLE_USERNAME'] = user_secrets.get_secret("kaggle_username")
    if not os.environ['KAGGLE_USERNAME']: raise Exception("Please insert your Kaggle username and key into Kaggle secrets")
    os.environ['KAGGLE_KEY'] = user_secrets.get_secret("kaggle_key")
    github_pat = user_secrets.get_secret("GITHUB_PAT")
    !pip install -Uqq git+https://{github_pat}@github.com/Rahuketu86/aiking
else:
    from aiking.data.external import *
    path = untar_data("kaggle_datasets::alexisbcook/geospatial-learn-course-data"); 
    print(path.ls())
[Path('/Users/rahul1.saraf/rahuketu/programming/AIKING_HOME/data/geospatial-learn-course-data/japan-prefecture-population.csv'), Path('/Users/rahul1.saraf/rahuketu/programming/AIKING_HOME/data/geospatial-learn-course-data/purple_martin.csv'), Path('/Users/rahul1.saraf/rahuketu/programming/AIKING_HOME/data/geospatial-learn-course-data/japan-prefecture-boundaries'), Path('/Users/rahul1.saraf/rahuketu/programming/AIKING_HOME/data/geospatial-learn-course-data/ghana'), Path('/Users/rahul1.saraf/rahuketu/programming/AIKING_HOME/data/geospatial-learn-course-data/toxic_release_pennsylvania'), Path('/Users/rahul1.saraf/rahuketu/programming/AIKING_HOME/data/geospatial-learn-course-data/Police_Districts'), Path('/Users/rahul1.saraf/rahuketu/programming/AIKING_HOME/data/geospatial-learn-course-data/CA_county_median_age.csv'), Path('/Users/rahul1.saraf/rahuketu/programming/AIKING_HOME/data/geospatial-learn-course-data/crimes-in-boston'), Path('/Users/rahul1.saraf/rahuketu/programming/AIKING_HOME/data/geospatial-learn-course-data/earthquakes1970-2014.csv'), Path('/Users/rahul1.saraf/rahuketu/programming/AIKING_HOME/data/geospatial-learn-course-data/top_universities.csv'), Path('/Users/rahul1.saraf/rahuketu/programming/AIKING_HOME/data/geospatial-learn-course-data/DEC_pointsinterest'), Path('/Users/rahul1.saraf/rahuketu/programming/AIKING_HOME/data/geospatial-learn-course-data/starbucks_locations.csv'), Path('/Users/rahul1.saraf/rahuketu/programming/AIKING_HOME/data/geospatial-learn-course-data/nyu_2451_34494'), Path('/Users/rahul1.saraf/rahuketu/programming/AIKING_HOME/data/geospatial-learn-course-data/DEC_roadstrails'), Path('/Users/rahul1.saraf/rahuketu/programming/AIKING_HOME/data/geospatial-learn-course-data/Philippines_AL258.kml'), Path('/Users/rahul1.saraf/rahuketu/programming/AIKING_HOME/data/geospatial-learn-course-data/PhillyHealth_Air_Monitoring_Stations'), Path('/Users/rahul1.saraf/rahuketu/programming/AIKING_HOME/data/geospatial-learn-course-data/Plate_Boundaries'), Path('/Users/rahul1.saraf/rahuketu/programming/AIKING_HOME/data/geospatial-learn-course-data/NY_county_boundaries'), Path('/Users/rahul1.saraf/rahuketu/programming/AIKING_HOME/data/geospatial-learn-course-data/CA_county_population.csv'), Path('/Users/rahul1.saraf/rahuketu/programming/AIKING_HOME/data/geospatial-learn-course-data/CA_county_high_earners.csv'), Path('/Users/rahul1.saraf/rahuketu/programming/AIKING_HOME/data/geospatial-learn-course-data/ex4_files'), Path('/Users/rahul1.saraf/rahuketu/programming/AIKING_HOME/data/geospatial-learn-course-data/kiva_loans'), Path('/Users/rahul1.saraf/rahuketu/programming/AIKING_HOME/data/geospatial-learn-course-data/SAPA_Aug2019-shapefile'), Path('/Users/rahul1.saraf/rahuketu/programming/AIKING_HOME/data/geospatial-learn-course-data/NYPD_Motor_Vehicle_Collisions'), Path('/Users/rahul1.saraf/rahuketu/programming/AIKING_HOME/data/geospatial-learn-course-data/CA_county_boundaries'), Path('/Users/rahul1.saraf/rahuketu/programming/AIKING_HOME/data/geospatial-learn-course-data/DEC_lands')]

Read the Dataset

data_dir = pathlib.Path(os.getenv('DATA_DIR', "/kaggle/input"));data_dir
path = data_dir/"geospatial-learn-course-data"
path
Path('/Users/rahul1.saraf/rahuketu/programming/AIKING_HOME/data/geospatial-learn-course-data')
full_data = gpd.read_file(path/"DEC_lands/DEC_lands/DEC_lands.shp"); full_data.head().T
0 1 2 3 4
OBJECTID 1 2 3 4 6
CATEGORY FOR PRES DET PAR FOR PRES DET PAR FOR PRES DET PAR FOR PRES DET PAR FOREST PRESERVE
UNIT CFP CFP CFP CFP AFP
FACILITY HANCOCK FP DETACHED PARCEL HANCOCK FP DETACHED PARCEL HANCOCK FP DETACHED PARCEL GREENE COUNTY FP DETACHED PARCEL SARANAC LAKES WILD FOREST
CLASS WILD FOREST WILD FOREST WILD FOREST WILD FOREST WILD FOREST
UMP None None None None SARANAC LAKES
DESCRIPTIO DELAWARE COUNTY DETACHED PARCEL DELAWARE COUNTY DETACHED PARCEL DELAWARE COUNTY DETACHED PARCEL None None
REGION 4 4 4 4 5
COUNTY DELAWARE DELAWARE DELAWARE GREENE ESSEX
URL http://www.dec.ny.gov/ http://www.dec.ny.gov/ http://www.dec.ny.gov/ http://www.dec.ny.gov/ http://www.dec.ny.gov/lands/22593.html
SOURCE DELAWARE RPP DELAWARE RPP DELAWARE RPP GREENE RPP DECRP, ESSEX RPP
UPDATE_ 5/12 5/12 5/12 5/12 12/96
OFFICE STAMFORD STAMFORD STAMFORD STAMFORD RAY BROOK
ACRES 738.620192 282.55314 234.291262 450.106464 69.702387
LANDS_UID 103 1218 1780 2060 1517
GREENCERT N N N N N
SHAPE_AREA 2990365.14969 1143939.83963 948547.620235 1822293.3747 282195.899084
SHAPE_LEN 7927.662385 4776.3756 5783.070364 7021.644833 2663.909932
geometry POLYGON ((486093.24450000003 4635308.5855, 486787.2352999998 4635115.7457, 486976.39499999955 4635808.6964, 487488.81799999997 4635655.977499999, 487335.70639999956 4635130.978, 487797.0881000003 4634992.676999999, 487560.1246999996 4634220.9705, 487383.92399999965 4633637.5305, 487373.7348999996 4633601.4958999995, 487220.7814999996 4633049.9625, 487162.38709999993 4633042.8791000005, 487090.8465 4633044.3104, 486989.4759999998 4633062.357899999, 486934.3454999998 4633077.335100001, 486818.83719999995 4633119.740700001, 486756.93290000036 4633145.081599999, 486684.10610000044 4633180.4495... POLYGON ((491931.51379999984 4637416.256200001, 491305.42420000024 4637642.459100001, 491578.70100000035 4638441.0155, 491853.32650000043 4639265.596000001, 492483.3805999998 4639061.368799999, 492203.5235000001 4638218.9037, 491931.51379999984 4637416.256200001)) POLYGON ((486000.28670000006 4635834.4528, 485007.55040000007 4636099.234099999, 485032.8816999998 4636191.4736, 485044.0120000001 4636207.050799999, 485048.11670000013 4636230.219699999, 485046.8596000001 4636242.5305, 485046.94600000046 4636267.019200001, 485050.38609999977 4636272.7215, 485178.89609999955 4636782.7128, 486155.8295 4636459.9759, 486212.5314999996 4636680.360200001, 487135.3630999997 4636424.270500001, 487067.89520000014 4636163.0505, 486146.9922000002 4636423.383300001, 486015.9768000003 4635896.366599999, 486000.28670000006 4635834.4528)) POLYGON ((541716.7752999999 4675243.268100001, 541217.5795 4675518.876, 540717.6582000004 4675794.796, 541048.6458 4676427.3598, 540579.7456999999 4676682.7578, 540961.7325999998 4677410.7522, 541442.4759999998 4677153.9682, 541549.0955999997 4677097.0185, 541501.0888 4677056.1578, 541456.8405999998 4677040.375600001, 541403.3485000003 4676980.9888, 541319.7302999999 4676845.1779, 541257.7050000001 4676688.383199999, 541263.5816000002 4676655.3248, 541289.5584000004 4676548.8949, 541461.4754999997 4676564.4405000005, 541483.8139000004 4676566.724400001, 541530.1478000004 4676578.0439, 5415... POLYGON ((583896.0428999998 4909643.187000001, 583891.2004000004 4909650.000700001, 583888.7213000003 4909656.818499999, 583885.9994999999 4909664.299799999, 583894.5007999996 4909674.9013, 583909.5997000001 4909679.600400001, 583912.3583000004 4909680.4657000005, 583914.7001999998 4909681.199899999, 583916.5279999999 4909683.010399999, 583925.4000000004 4909691.8004, 583929.8000999996 4909711.9998, 583949.9994999999 4909723.5997, 584000.0004000003 4909739.5997, 584058.5998 4909738.0012, 584105.0987 4909745.245999999, 584109.3000999996 4909745.9003, 584127.1996999998 4909760.100099999, 584...
type(full_data)
geopandas.geodataframe.GeoDataFrame
full_data.columns
Index(['OBJECTID', 'CATEGORY', 'UNIT', 'FACILITY', 'CLASS', 'UMP',
       'DESCRIPTIO', 'REGION', 'COUNTY', 'URL', 'SOURCE', 'UPDATE_', 'OFFICE',
       'ACRES', 'LANDS_UID', 'GREENCERT', 'SHAPE_AREA', 'SHAPE_LEN',
       'geometry'],
      dtype='object')
data = full_data.loc[:, ["CLASS", "COUNTY", "geometry"]].copy(); data.head()
CLASS COUNTY geometry
0 WILD FOREST DELAWARE POLYGON ((486093.245 4635308.586, 486787.235 4635115.746, 486976.395 4635808.696, 487488.818 4635655.977, 487335.706 4635130.978, 487797.088 4634992.677, 487560.125 4634220.970, 487383.924 4633637.531, 487373.735 4633601.496, 487220.781 4633049.963, 487162.387 4633042.879, 487090.846 4633044.310, 486989.476 4633062.358, 486934.345 4633077.335, 486818.837 4633119.741, 486756.933 4633145.082, 486684.106 4633180.450, 486608.054 4633219.201, 486578.667 4633239.386, 486539.958 4633269.401, 486463.134 4633337.644, 486404.675 4633401.192, 486362.180 4633465.284, 486327.840 4633556.841, 486309.883...
1 WILD FOREST DELAWARE POLYGON ((491931.514 4637416.256, 491305.424 4637642.459, 491578.701 4638441.015, 491853.327 4639265.596, 492483.381 4639061.369, 492203.524 4638218.904, 491931.514 4637416.256))
2 WILD FOREST DELAWARE POLYGON ((486000.287 4635834.453, 485007.550 4636099.234, 485032.882 4636191.474, 485044.012 4636207.051, 485048.117 4636230.220, 485046.860 4636242.531, 485046.946 4636267.019, 485050.386 4636272.721, 485178.896 4636782.713, 486155.829 4636459.976, 486212.531 4636680.360, 487135.363 4636424.271, 487067.895 4636163.050, 486146.992 4636423.383, 486015.977 4635896.367, 486000.287 4635834.453))
3 WILD FOREST GREENE POLYGON ((541716.775 4675243.268, 541217.579 4675518.876, 540717.658 4675794.796, 541048.646 4676427.360, 540579.746 4676682.758, 540961.733 4677410.752, 541442.476 4677153.968, 541549.096 4677097.019, 541501.089 4677056.158, 541456.841 4677040.376, 541403.349 4676980.989, 541319.730 4676845.178, 541257.705 4676688.383, 541263.582 4676655.325, 541289.558 4676548.895, 541461.475 4676564.441, 541483.814 4676566.724, 541530.148 4676578.044, 541558.074 4676588.519, 541612.088 4676600.662, 541682.091 4676591.397, 541686.528 4676591.020, 541728.308 4676598.203, 541768.703 4676603.194, 541796.887...
4 WILD FOREST ESSEX POLYGON ((583896.043 4909643.187, 583891.200 4909650.001, 583888.721 4909656.818, 583885.999 4909664.300, 583894.501 4909674.901, 583909.600 4909679.600, 583912.358 4909680.466, 583914.700 4909681.200, 583916.528 4909683.010, 583925.400 4909691.800, 583929.800 4909712.000, 583949.999 4909723.600, 584000.000 4909739.600, 584058.600 4909738.001, 584105.099 4909745.246, 584109.300 4909745.900, 584127.200 4909760.100, 584141.600 4909817.000, 584131.200 4909877.500, 584120.599 4909918.900, 584087.100 4909945.700, 584006.900 4909938.600, 583933.900 4909948.000, 583933.880 4909948.010, 583942.311...
data.CLASS.value_counts()
CLASS
WILD FOREST                   965
INTENSIVE USE                 108
PRIMITIVE                      60
WILDERNESS                     52
ADMINISTRATIVE                 17
UNCLASSIFIED                    7
HISTORIC                        5
PRIMITIVE BICYCLE CORRIDOR      4
CANOE AREA                      1
Name: count, dtype: int64
data.COUNTY.value_counts()
COUNTY
HAMILTON        240
SUFFOLK         239
ST. LAWRENCE    214
ESSEX           208
FRANKLIN        166
WARREN          114
LEWIS           113
CLINTON         108
ULSTER          101
ONEIDA           96
OSWEGO           87
HERKIMER         82
FULTON           66
DELAWARE         66
SARATOGA         65
GREENE           60
CHENANGO         56
JEFFERSON        52
CATTARAUGUS      48
ALBANY           47
SULLIVAN         47
ALLEGANY         42
MADISON          40
WASHINGTON       40
CHAUTAUQUA       39
STEUBEN          36
SCHOHARIE        33
OTSEGO           32
CORTLAND         32
COLUMBIA         29
PUTNAM           28
WAYNE            28
ORANGE           27
DUTCHESS         25
ONONDAGA         25
RICHMOND         23
MONROE           18
TOMPKINS         18
BROOME           18
CAYUGA           18
SCHUYLER         17
LIVINGSTON       15
RENSSELAER       14
ONTARIO          13
TIOGA            12
ERIE             12
WYOMING          11
YATES            10
NASSAU            9
SENECA            9
GENESEE           7
MONTGOMERY        5
CHEMUNG           5
WESTCHESTER       4
NIAGARA           3
BRONX             3
ROCKLAND          3
QUEENS            3
SCHENECTADY       2
Name: count, dtype: int64
data.info()
<class 'geopandas.geodataframe.GeoDataFrame'>
RangeIndex: 2983 entries, 0 to 2982
Data columns (total 3 columns):
 #   Column    Non-Null Count  Dtype   
---  ------    --------------  -----   
 0   CLASS     1219 non-null   object  
 1   COUNTY    2983 non-null   object  
 2   geometry  2983 non-null   geometry
dtypes: geometry(1), object(2)
memory usage: 70.0+ KB
data.describe().T
count unique top freq
CLASS 1219 9 WILD FOREST 965
COUNTY 2983 59 HAMILTON 240
geometry 2983 2982 POLYGON ((556190.0366000002 4945182.626499999, 556301.9720999999 4945216.9419, 556301.6024000002 4945216.6798, 556315.9544000002 4945221.228399999, 556301.9720999999 4945216.9419, 556315.8447000002 4945226.7782000005, 556323.6621000003 4945228.172900001, 556326.4691000003 4945231.1905000005, 556326.6166000003 4945233.5208, 556331.2366000004 4945238.8825, 556336.2088000001 4945241.9176, 556346.0181999998 4945244.160499999, 556350.9834000003 4945248.0275, 556352.9495000001 4945252.036599999, 556367.1427999996 4945268.1239, 556373.8639000002 4945272.9838, 556377.6853 4945274.179500001, 556386... 2
# Select lands that fall under the "WILD FOREST" or "WILDERNESS" category
wild_lands = data.loc[data.CLASS.isin(['WILD FOREST', 'WILDERNESS'])].copy(); wild_lands.head()
CLASS COUNTY geometry
0 WILD FOREST DELAWARE POLYGON ((486093.245 4635308.586, 486787.235 4635115.746, 486976.395 4635808.696, 487488.818 4635655.977, 487335.706 4635130.978, 487797.088 4634992.677, 487560.125 4634220.970, 487383.924 4633637.531, 487373.735 4633601.496, 487220.781 4633049.963, 487162.387 4633042.879, 487090.846 4633044.310, 486989.476 4633062.358, 486934.345 4633077.335, 486818.837 4633119.741, 486756.933 4633145.082, 486684.106 4633180.450, 486608.054 4633219.201, 486578.667 4633239.386, 486539.958 4633269.401, 486463.134 4633337.644, 486404.675 4633401.192, 486362.180 4633465.284, 486327.840 4633556.841, 486309.883...
1 WILD FOREST DELAWARE POLYGON ((491931.514 4637416.256, 491305.424 4637642.459, 491578.701 4638441.015, 491853.327 4639265.596, 492483.381 4639061.369, 492203.524 4638218.904, 491931.514 4637416.256))
2 WILD FOREST DELAWARE POLYGON ((486000.287 4635834.453, 485007.550 4636099.234, 485032.882 4636191.474, 485044.012 4636207.051, 485048.117 4636230.220, 485046.860 4636242.531, 485046.946 4636267.019, 485050.386 4636272.721, 485178.896 4636782.713, 486155.829 4636459.976, 486212.531 4636680.360, 487135.363 4636424.271, 487067.895 4636163.050, 486146.992 4636423.383, 486015.977 4635896.367, 486000.287 4635834.453))
3 WILD FOREST GREENE POLYGON ((541716.775 4675243.268, 541217.579 4675518.876, 540717.658 4675794.796, 541048.646 4676427.360, 540579.746 4676682.758, 540961.733 4677410.752, 541442.476 4677153.968, 541549.096 4677097.019, 541501.089 4677056.158, 541456.841 4677040.376, 541403.349 4676980.989, 541319.730 4676845.178, 541257.705 4676688.383, 541263.582 4676655.325, 541289.558 4676548.895, 541461.475 4676564.441, 541483.814 4676566.724, 541530.148 4676578.044, 541558.074 4676588.519, 541612.088 4676600.662, 541682.091 4676591.397, 541686.528 4676591.020, 541728.308 4676598.203, 541768.703 4676603.194, 541796.887...
4 WILD FOREST ESSEX POLYGON ((583896.043 4909643.187, 583891.200 4909650.001, 583888.721 4909656.818, 583885.999 4909664.300, 583894.501 4909674.901, 583909.600 4909679.600, 583912.358 4909680.466, 583914.700 4909681.200, 583916.528 4909683.010, 583925.400 4909691.800, 583929.800 4909712.000, 583949.999 4909723.600, 584000.000 4909739.600, 584058.600 4909738.001, 584105.099 4909745.246, 584109.300 4909745.900, 584127.200 4909760.100, 584141.600 4909817.000, 584131.200 4909877.500, 584120.599 4909918.900, 584087.100 4909945.700, 584006.900 4909938.600, 583933.900 4909948.000, 583933.880 4909948.010, 583942.311...
wild_lands.plot()

wild_lands.geometry.head()
0    POLYGON ((486093.245 4635308.586, 486787.235 4635115.746, 486976.395 4635808.696, 487488.818 4635655.977, 487335.706 4635130.978, 487797.088 4634992.677, 487560.125 4634220.970, 487383.924 4633637.531, 487373.735 4633601.496, 487220.781 4633049.963, 487162.387 4633042.879, 487090.846 4633044.310, 486989.476 4633062.358, 486934.345 4633077.335, 486818.837 4633119.741, 486756.933 4633145.082, 486684.106 4633180.450, 486608.054 4633219.201, 486578.667 4633239.386, 486539.958 4633269.401, 486463.134 4633337.644, 486404.675 4633401.192, 486362.180 4633465.284, 486327.840 4633556.841, 486309.883...
1                                                                                                                                                                                                                                                                                                                                                                                                                                         POLYGON ((491931.514 4637416.256, 491305.424 4637642.459, 491578.701 4638441.015, 491853.327 4639265.596, 492483.381 4639061.369, 492203.524 4638218.904, 491931.514 4637416.256))
2                                                                                                                                                                                                                 POLYGON ((486000.287 4635834.453, 485007.550 4636099.234, 485032.882 4636191.474, 485044.012 4636207.051, 485048.117 4636230.220, 485046.860 4636242.531, 485046.946 4636267.019, 485050.386 4636272.721, 485178.896 4636782.713, 486155.829 4636459.976, 486212.531 4636680.360, 487135.363 4636424.271, 487067.895 4636163.050, 486146.992 4636423.383, 486015.977 4635896.367, 486000.287 4635834.453))
3    POLYGON ((541716.775 4675243.268, 541217.579 4675518.876, 540717.658 4675794.796, 541048.646 4676427.360, 540579.746 4676682.758, 540961.733 4677410.752, 541442.476 4677153.968, 541549.096 4677097.019, 541501.089 4677056.158, 541456.841 4677040.376, 541403.349 4676980.989, 541319.730 4676845.178, 541257.705 4676688.383, 541263.582 4676655.325, 541289.558 4676548.895, 541461.475 4676564.441, 541483.814 4676566.724, 541530.148 4676578.044, 541558.074 4676588.519, 541612.088 4676600.662, 541682.091 4676591.397, 541686.528 4676591.020, 541728.308 4676598.203, 541768.703 4676603.194, 541796.887...
4    POLYGON ((583896.043 4909643.187, 583891.200 4909650.001, 583888.721 4909656.818, 583885.999 4909664.300, 583894.501 4909674.901, 583909.600 4909679.600, 583912.358 4909680.466, 583914.700 4909681.200, 583916.528 4909683.010, 583925.400 4909691.800, 583929.800 4909712.000, 583949.999 4909723.600, 584000.000 4909739.600, 584058.600 4909738.001, 584105.099 4909745.246, 584109.300 4909745.900, 584127.200 4909760.100, 584141.600 4909817.000, 584131.200 4909877.500, 584120.599 4909918.900, 584087.100 4909945.700, 584006.900 4909938.600, 583933.900 4909948.000, 583933.880 4909948.010, 583942.311...
Name: geometry, dtype: geometry

Adding 3 more geodataframes :-

  • Campsite locations [Point]
  • Foot trails [Line String]
  • County boundaries [Polygon]
# Campsites in New York state (Point)
POI_data = gpd.read_file(path/"DEC_pointsinterest/DEC_pointsinterest/Decptsofinterest.shp")
campsites = POI_data.loc[POI_data.ASSET=='PRIMITIVE CAMPSITE'].copy(); campsites.head().T
0 1 2 5 6
OBJECTID 91706 108646 19933 39673 19434
UNIT CFP SCHUYLER 02 AFP AFP AFP
FACILITY DELAWARE WILD FOREST SUGAR HILL STATE FOREST MOOSE RIVER PLAINS WILD FOREST SARANAC LAKES WILD FOREST LAKE GEORGE WILD FOREST
NAME ADA PRIMITIVE CAMPSITE MAPLE LANE CAMPSITE #3 MOOSE RIVER PLAINS CAMPSITE 103 SARANAC ISLANDS CAMPGROUND SITE 27 GAY POND ROAD CAMPSITE 13
ASSET PRIMITIVE CAMPSITE PRIMITIVE CAMPSITE PRIMITIVE CAMPSITE PRIMITIVE CAMPSITE PRIMITIVE CAMPSITE
DESCRIP None None LIVE None DESIGNATED CAMPSITE WITH ACCESSIBLE PRIVY AND FIRE RING
REGION 4 8 5 5 5
OFFICE STAMFORD BATH NORTHVILLE RAY BROOK WARRENSBURG
UPDATED 2016-09-26 2018-02-23 2010-06-16 2012-01-09 2010-05-24
ASSET_UID 16519 18124 1018 5337 3030
ACCESSIBLE N N N N Y
geometry POINT (505138.6961690886 4649388.24743947) POINT (333481.8738652207 4692737.800375842) POINT (525210.7837397819 4833837.295163251) POINT (562996.4824629724 4904871.884925406) POINT (591292.4023613259 4807432.221986659)
# Foot trails in New York state (LineString)
roads_trails = gpd.read_file(path/"DEC_roadstrails/DEC_roadstrails/Decroadstrails.shp")
trails = roads_trails.loc[roads_trails.ASSET=='FOOT TRAIL'].copy(); trails.head().T
31 34 35 37 38
OBJECTID 304 311 312 314 317
UNIT AFP AFP AFP AFP AFP
FACILITY DEBAR MOUNTAIN WILD FOREST DEBAR MOUNTAIN WILD FOREST DEBAR MOUNTAIN WILD FOREST DEBAR MOUNTAIN WILD FOREST DEBAR MOUNTAIN WILD FOREST
NAME MAIN BRANCH CANOE CARRY CAMP SITE ACCESS TRAIL ACCESS TRAIL EAST BRANCH CANOE CARRY RAINBOW LAKE TO JONES POND CANOE CARRY
ASSET FOOT TRAIL FOOT TRAIL FOOT TRAIL FOOT TRAIL FOOT TRAIL
ATV N N N N N
FOOT M Y Y Y Y
HORSE N N N N N
BIKE N N N N N
XC N N N Y Y
MOTORV N N N N N
SNOWMB N N N N N
ADMIN Y N N N N
ACCESSIBLE N N N N N
MAPPWD N N N N N
DESCRIP None None None None None
ROAD_CLASS RT RT RT RT RT
UPDATED 2006-08-24 2011-04-19 2011-04-19 2006-08-24 2011-04-19
REGION 5 5 5 5 5
OFFICE RAY BROOK RAY BROOK RAY BROOK RAY BROOK RAY BROOK
MARKER None None None None None
TRANS_UID 244.7761 163.203974 117.720119 386.073522 127.460965
SHAPE_LEN 246.427662 163.203974 117.720119 386.073522 127.460965
geometry LINESTRING (542463.27680742 4933622.420835145, 542429.2390473876 4933523.6007390525, 542288.3765832568 4933506.391395036) LINESTRING (564033.3747475082 4922561.920728844, 564100.3425555704 4922413.089112705) LINESTRING (564202.3599636657 4922745.700057015, 564298.863387756 4922678.282584952) LINESTRING (547547.4214521544 4942827.827563718, 547629.1724922312 4943013.977451891, 547806.2302843956 4943059.287403934) LINESTRING (564759.8379801847 4923577.415513789, 564654.6300440868 4923505.460057722)
# County boundaries in New York state (Polygon)
counties = gpd.read_file(path/"NY_county_boundaries/NY_county_boundaries/NY_county_boundaries.shp"); counties.head().T
0 1 2 3 4
STATE 36 36 36 36 36
COUNTY 089 019 033 031 045
NAME St. Lawrence Clinton Franklin Essex Jefferson
LSAD 06 06 06 06 06
LSAD_TRANS County County County County County
... ... ... ... ... ...
RURAL 33636 20930 16527 18827 33123
VACANT 9215 3668 6005 8087 14002
OWNER_OCC 28606 20157 12638 11089 23906
RENTER_OCC 11900 9266 5293 3939 16162
geometry POLYGON ((522686.11586778064 4977770.43451575, 522785.8198053561 4977770.7888964815, 524354.0304587879 4977775.678587283, 524399.8192495668 4977765.744071741, 524493.6111999404 4977765.102730145, 526158.0318291239 4977758.028642864, 526206.0729439257 4977757.4476590445, 528249.2175655201 4977749.592102337, 528731.8305382137 4973105.031722965, 528801.7681174324 4972403.159946137, 529129.2272695601 4969174.216304761, 529189.9187993364 4968508.191519112, 529230.3418945112 4968062.361048206, 529270.0364101009 4967586.867560315, 529293.6479504965 4967399.016223953, 529334.3704145666 4967132.593... POLYGON ((576869.5537551416 4981194.983888856, 576661.3232085826 4982940.04212441, 588697.0930262735 4983702.269107748, 593370.3946983537 4983887.885680857, 597490.2236920536 4984054.364751626, 604388.9052717009 4984126.653933049, 606235.7801659611 4984197.715210815, 607204.5836333224 4984235.205607117, 613463.8862965327 4984593.653152056, 615884.0705838657 4984733.904181708, 616687.1609977577 4984780.647803647, 621941.4898320807 4985088.983992265, 623139.3802293361 4985159.888493991, 625203.205194697 4985250.77103897, 627004.4540100332 4985330.638177465, 628651.5290325196 4985404.11586663... POLYGON ((576869.5537551416 4981194.983888856, 577209.2586512418 4978844.140691264, 577209.4437403396 4978828.810744761, 577518.6448222906 4976708.156704487, 577667.9541977715 4975874.809723736, 578278.3580580656 4972242.08819902, 578441.0466523991 4970762.644135055, 578519.3876323651 4969279.728571323, 578509.6303886175 4965316.406335834, 578810.0880832829 4963255.166918222, 578969.8725403768 4962182.563589267, 579018.6189751457 4961910.077606817, 579024.4584274306 4961846.8221210055, 579027.9182209704 4961809.868198515, 579079.0542153715 4961304.878942508, 579118.7830764937 4960988.17611... POLYGON ((622025.3618710961 4932488.54527187, 621958.0493959482 4932585.508301904, 622042.9990985517 4932742.448869401, 627060.6289166632 4933358.595094804, 631969.7035735992 4933954.88883335, 631927.2258875349 4933720.638464426, 631921.8296738676 4933690.881575875, 631948.7130833236 4933560.856271277, 632539.0762520169 4932772.3053018255, 632553.3084662243 4932753.298203195, 632612.839083322 4932570.601946062, 632636.8412491266 4932297.841377374, 632644.4167473195 4932211.756543417, 632738.3620251643 4932010.206678062, 632815.1779268526 4931931.21222726, 633181.960043119 4931787.819605775... POLYGON ((431513.3160732966 4917024.859650368, 433126.7238355884 4915958.450947802, 434408.11971884995 4915109.176162795, 438982.2038404562 4912112.929346125, 440129.95918553416 4911381.257012523, 441404.952578037 4910605.437972185, 443710.11001012695 4909045.227899764, 443820.21532854025 4908970.6327789035, 446201.37730085244 4907485.319871183, 446522.3087661563 4907302.513120494, 448581.11957705335 4906069.110311733, 449750.6634752473 4905354.884339001, 452695.9911564786 4903566.100546615, 452987.44783580577 4903383.386535222, 453118.92197992286 4903300.911794116, 456373.960437575 490128...

81 rows × 5 columns

Visualize

ax = counties.plot(figsize=(10,10), color='none', edgecolor='gainsboro', zorder=3);ax

ax = counties.plot(figsize=(10,10), color='none', edgecolor='gainsboro', zorder=3);ax
wild_lands.plot(color='lightgreen', ax=ax)
campsites.plot(color='maroon', markersize=2, ax=ax)
trails.plot(color='black', markersize=1, ax=ax)

Conclusion

Looks like the northeastern part of the state would be a great option for a camping trip!

Exercise

Question

Identify remote areas of the Philippines where a non-profit can expand its operations.

loans_data = gpd.read_file(path/"kiva_loans/kiva_loans/kiva_loans.shp"); loans_data.head().T
0 1 2 3 4
Partner ID 9 9 9 9 9
Field Part KREDIT Microfinance Institution KREDIT Microfinance Institution KREDIT Microfinance Institution KREDIT Microfinance Institution KREDIT Microfinance Institution
sector General Financial Inclusion General Financial Inclusion General Financial Inclusion General Financial Inclusion General Financial Inclusion
Loan Theme Higher Education Vulnerable Populations Higher Education Vulnerable Populations Sanitation
country Cambodia Cambodia Cambodia Cambodia Cambodia
amount 450 20275 9150 604950 275
geometry POINT (102.8975098 13.6672596) POINT (102.989615 13.028697099999999) POINT (102.989615 13.028697099999999) POINT (105.3131185 12.0982918) POINT (105.3131185 12.0982918)
world_filepath = gpd.datasets.get_path("naturalearth_lowres") ## Dataset containing country boundaries
world = gpd.read_file(world_filepath)
world
/var/folders/df/3bwv425110q0kc25hg9gcjw1nrdglc/T/ipykernel_8893/1830171302.py:1: FutureWarning: The geopandas.dataset module is deprecated and will be removed in GeoPandas 1.0. You can get the original 'naturalearth_lowres' data from https://www.naturalearthdata.com/downloads/110m-cultural-vectors/.
  world_filepath = gpd.datasets.get_path("naturalearth_lowres") ## Dataset containing country boundaries
pop_est continent name iso_a3 gdp_md_est geometry
0 889953.0 Oceania Fiji FJI 5496 MULTIPOLYGON (((180.00000 -16.06713, 180.00000 -16.55522, 179.36414 -16.80135, 178.72506 -17.01204, 178.59684 -16.63915, 179.09661 -16.43398, 179.41351 -16.37905, 180.00000 -16.06713)), ((178.12557 -17.50481, 178.37360 -17.33992, 178.71806 -17.62846, 178.55271 -18.15059, 177.93266 -18.28799, 177.38146 -18.16432, 177.28504 -17.72465, 177.67087 -17.38114, 178.12557 -17.50481)), ((-179.79332 -16.02088, -179.91737 -16.50178, -180.00000 -16.55522, -180.00000 -16.06713, -179.79332 -16.02088)))
1 58005463.0 Africa Tanzania TZA 63177 POLYGON ((33.90371 -0.95000, 34.07262 -1.05982, 37.69869 -3.09699, 37.76690 -3.67712, 39.20222 -4.67677, 38.74054 -5.90895, 38.79977 -6.47566, 39.44000 -6.84000, 39.47000 -7.10000, 39.19469 -7.70390, 39.25203 -8.00781, 39.18652 -8.48551, 39.53574 -9.11237, 39.94960 -10.09840, 40.31659 -10.31710, 40.31659 -10.31710, 39.52100 -10.89688, 38.42756 -11.28520, 37.82764 -11.26879, 37.47129 -11.56876, 36.77515 -11.59454, 36.51408 -11.72094, 35.31240 -11.43915, 34.55999 -11.52002, 34.28000 -10.16000, 33.94084 -9.69367, 33.73972 -9.41715, 32.75938 -9.23060, 32.19186 -8.93036, 31.55635 -8.76205, 31.1...
2 603253.0 Africa W. Sahara ESH 907 POLYGON ((-8.66559 27.65643, -8.66512 27.58948, -8.68440 27.39574, -8.68729 25.88106, -11.96942 25.93335, -11.93722 23.37459, -12.87422 23.28483, -13.11875 22.77122, -12.92910 21.32707, -16.84519 21.33332, -17.06342 20.99975, -17.02043 21.42231, -17.00296 21.42073, -14.75095 21.50060, -14.63083 21.86094, -14.22117 22.31016, -13.89111 23.69101, -12.50096 24.77012, -12.03076 26.03087, -11.71822 26.10409, -11.39255 26.88342, -10.55126 26.99081, -10.18942 26.86094, -9.73534 26.86094, -9.41304 27.08848, -8.79488 27.12070, -8.81783 27.65643, -8.66559 27.65643))
3 37589262.0 North America Canada CAN 1736425 MULTIPOLYGON (((-122.84000 49.00000, -122.97421 49.00254, -124.91024 49.98456, -125.62461 50.41656, -127.43561 50.83061, -127.99276 51.71583, -127.85032 52.32961, -129.12979 52.75538, -129.30523 53.56159, -130.51497 54.28757, -130.53611 54.80275, -130.53611 54.80278, -129.98000 55.28500, -130.00778 55.91583, -131.70781 56.55212, -132.73042 57.69289, -133.35556 58.41028, -134.27111 58.86111, -134.94500 59.27056, -135.47583 59.78778, -136.47972 59.46389, -137.45250 58.90500, -138.34089 59.56211, -139.03900 60.00000, -140.01300 60.27682, -140.99778 60.30639, -140.99250 66.00003, -140.98600 69...
4 328239523.0 North America United States of America USA 21433226 MULTIPOLYGON (((-122.84000 49.00000, -120.00000 49.00000, -117.03121 49.00000, -116.04818 49.00000, -113.00000 49.00000, -110.05000 49.00000, -107.05000 49.00000, -104.04826 48.99986, -100.65000 49.00000, -97.22872 49.00070, -95.15907 49.00000, -95.15609 49.38425, -94.81758 49.38905, -94.64000 48.84000, -94.32914 48.67074, -93.63087 48.60926, -92.61000 48.45000, -91.64000 48.14000, -90.83000 48.27000, -89.60000 48.01000, -89.27292 48.01981, -88.37811 48.30292, -87.43979 47.94000, -86.46199 47.55334, -85.65236 47.22022, -84.87608 46.90008, -84.77924 46.63710, -84.54375 46.53868, -84.60490 4...
... ... ... ... ... ... ...
172 6944975.0 Europe Serbia SRB 51475 POLYGON ((18.82982 45.90887, 18.82984 45.90888, 19.59604 46.17173, 20.22019 46.12747, 20.76217 45.73457, 20.87431 45.41638, 21.48353 45.18117, 21.56202 44.76895, 22.14509 44.47842, 22.45902 44.70252, 22.70573 44.57800, 22.47401 44.40923, 22.65715 44.23492, 22.41045 44.00806, 22.50016 43.64281, 22.98602 43.21116, 22.60480 42.89852, 22.43659 42.58032, 22.54501 42.46136, 22.38053 42.32026, 21.91708 42.30364, 21.57664 42.24522, 21.54332 42.32025, 21.66292 42.43922, 21.77505 42.68270, 21.63302 42.67717, 21.43866 42.86255, 21.27421 42.90959, 21.14340 43.06869, 20.95651 43.13094, 20.81448 43.2720...
173 622137.0 Europe Montenegro MNE 5542 POLYGON ((20.07070 42.58863, 19.80161 42.50009, 19.73805 42.68825, 19.30449 42.19575, 19.37177 41.87755, 19.16246 41.95502, 18.88214 42.28151, 18.45002 42.47999, 18.56000 42.65000, 18.70648 43.20011, 19.03165 43.43253, 19.21852 43.52384, 19.48389 43.35229, 19.63000 43.21378, 19.95857 43.10604, 20.33980 42.89852, 20.25758 42.81275, 20.07070 42.58863))
174 1794248.0 Europe Kosovo -99 7926 POLYGON ((20.59025 41.85541, 20.52295 42.21787, 20.28375 42.32026, 20.07070 42.58863, 20.25758 42.81275, 20.49679 42.88469, 20.63508 43.21671, 20.81448 43.27205, 20.95651 43.13094, 21.14340 43.06869, 21.27421 42.90959, 21.43866 42.86255, 21.63302 42.67717, 21.77505 42.68270, 21.66292 42.43922, 21.54332 42.32025, 21.57664 42.24522, 21.35270 42.20680, 20.76216 42.05186, 20.71731 41.84711, 20.59025 41.85541))
175 1394973.0 North America Trinidad and Tobago TTO 24269 POLYGON ((-61.68000 10.76000, -61.10500 10.89000, -60.89500 10.85500, -60.93500 10.11000, -61.77000 10.00000, -61.95000 10.09000, -61.66000 10.36500, -61.68000 10.76000))
176 11062113.0 Africa S. Sudan SSD 11998 POLYGON ((30.83385 3.50917, 29.95350 4.17370, 29.71600 4.60080, 29.15908 4.38927, 28.69668 4.45508, 28.42899 4.28715, 27.97998 4.40841, 27.37423 5.23394, 27.21341 5.55095, 26.46591 5.94672, 26.21342 6.54660, 25.79665 6.97932, 25.12413 7.50009, 25.11493 7.82510, 24.56737 8.22919, 23.88698 8.61973, 24.19407 8.72870, 24.53742 8.91754, 24.79493 9.81024, 25.06960 10.27376, 25.79063 10.41110, 25.96231 10.13642, 26.47733 9.55273, 26.75201 9.46689, 27.11252 9.63857, 27.83355 9.60423, 27.97089 9.39822, 28.96660 9.39822, 29.00093 9.60423, 29.51595 9.79307, 29.61896 10.08492, 29.99664 10.29093, 30.83...

177 rows × 6 columns

ax = world.plot(figsize=(10,10), color='whitesmoke', linestyle=':', edgecolor='black');ax
loans_data.plot(ax=ax, markersize=2)

a = loans_data.country.unique()
a.sort();a
array(['Afghanistan', 'Albania', 'Armenia', 'Azerbaijan', 'Belize',
       'Benin', 'Bhutan', 'Bolivia', 'Brazil', 'Burkina Faso', 'Burundi',
       'Cambodia', 'Cameroon', 'Canada', 'China', 'Colombia',
       'Costa Rica', "Cote D'Ivoire", 'Dominican Republic', 'Ecuador',
       'Egypt', 'El Salvador', 'Georgia', 'Ghana', 'Guatemala', 'Haiti',
       'Honduras', 'India', 'Indonesia', 'Israel', 'Jordan', 'Kenya',
       'Kosovo', 'Kyrgyzstan', "Lao People's Democratic Republic",
       'Lebanon', 'Lesotho', 'Liberia', 'Madagascar', 'Malawi', 'Mali',
       'Mexico', 'Moldova', 'Mongolia', 'Mozambique', 'Myanmar (Burma)',
       'Namibia', 'Nepal', 'Nicaragua', 'Nigeria', 'Pakistan',
       'Palestine', 'Panama', 'Paraguay', 'Peru', 'Philippines', 'Rwanda',
       'Samoa', 'Senegal', 'Sierra Leone', 'Solomon Islands', 'Somalia',
       'South Africa', 'South Sudan', 'Suriname', 'Tajikistan',
       'Tanzania', 'Thailand', 'The Democratic Republic of the Congo',
       'Timor-Leste', 'Togo', 'Turkey', 'Uganda', 'Ukraine',
       'United States', 'Vietnam', 'Yemen', 'Zambia', 'Zimbabwe'],
      dtype=object)
loans_data[loans_data.country =='Philippines']
Partner ID Field Part sector Loan Theme country amount geometry
2859 123 Alalay sa Kaunlaran (ASKI) General Financial Inclusion General Philippines 400 POINT (121.73961 17.64228)
2860 123 Alalay sa Kaunlaran (ASKI) General Financial Inclusion General Philippines 400 POINT (121.74169 17.63235)
2861 123 Alalay sa Kaunlaran (ASKI) General Financial Inclusion General Philippines 400 POINT (121.46667 16.60000)
2862 123 Alalay sa Kaunlaran (ASKI) General Financial Inclusion General Philippines 6050 POINT (121.73333 17.83333)
2863 123 Alalay sa Kaunlaran (ASKI) General Financial Inclusion General Philippines 625 POINT (121.51800 16.72368)
... ... ... ... ... ... ... ...
12376 389 SEED Center Philippines General Financial Inclusion Small Enterprise Philippines 11500 POINT (120.83841 14.35197)
12377 389 SEED Center Philippines General Financial Inclusion General Philippines 17050 POINT (120.83841 14.35197)
12378 389 SEED Center Philippines General Financial Inclusion Small Enterprise Philippines 24000 POINT (120.96597 14.62057)
12379 389 SEED Center Philippines General Financial Inclusion General Philippines 31725 POINT (120.96597 14.62057)
12380 389 SEED Center Philippines General Financial Inclusion General Philippines 5725 POINT (120.86138 14.28665)

3083 rows × 7 columns

country = 'Philippines'
ax = world[world.name ==  country].plot(figsize=(10,10), color='whitesmoke', linestyle=':', edgecolor='black');ax
loans_data[loans_data.country == country].plot(ax=ax, markersize=2)

world.name.unique()
array(['Fiji', 'Tanzania', 'W. Sahara', 'Canada',
       'United States of America', 'Kazakhstan', 'Uzbekistan',
       'Papua New Guinea', 'Indonesia', 'Argentina', 'Chile',
       'Dem. Rep. Congo', 'Somalia', 'Kenya', 'Sudan', 'Chad', 'Haiti',
       'Dominican Rep.', 'Russia', 'Bahamas', 'Falkland Is.', 'Norway',
       'Greenland', 'Fr. S. Antarctic Lands', 'Timor-Leste',
       'South Africa', 'Lesotho', 'Mexico', 'Uruguay', 'Brazil',
       'Bolivia', 'Peru', 'Colombia', 'Panama', 'Costa Rica', 'Nicaragua',
       'Honduras', 'El Salvador', 'Guatemala', 'Belize', 'Venezuela',
       'Guyana', 'Suriname', 'France', 'Ecuador', 'Puerto Rico',
       'Jamaica', 'Cuba', 'Zimbabwe', 'Botswana', 'Namibia', 'Senegal',
       'Mali', 'Mauritania', 'Benin', 'Niger', 'Nigeria', 'Cameroon',
       'Togo', 'Ghana', "Côte d'Ivoire", 'Guinea', 'Guinea-Bissau',
       'Liberia', 'Sierra Leone', 'Burkina Faso', 'Central African Rep.',
       'Congo', 'Gabon', 'Eq. Guinea', 'Zambia', 'Malawi', 'Mozambique',
       'eSwatini', 'Angola', 'Burundi', 'Israel', 'Lebanon', 'Madagascar',
       'Palestine', 'Gambia', 'Tunisia', 'Algeria', 'Jordan',
       'United Arab Emirates', 'Qatar', 'Kuwait', 'Iraq', 'Oman',
       'Vanuatu', 'Cambodia', 'Thailand', 'Laos', 'Myanmar', 'Vietnam',
       'North Korea', 'South Korea', 'Mongolia', 'India', 'Bangladesh',
       'Bhutan', 'Nepal', 'Pakistan', 'Afghanistan', 'Tajikistan',
       'Kyrgyzstan', 'Turkmenistan', 'Iran', 'Syria', 'Armenia', 'Sweden',
       'Belarus', 'Ukraine', 'Poland', 'Austria', 'Hungary', 'Moldova',
       'Romania', 'Lithuania', 'Latvia', 'Estonia', 'Germany', 'Bulgaria',
       'Greece', 'Turkey', 'Albania', 'Croatia', 'Switzerland',
       'Luxembourg', 'Belgium', 'Netherlands', 'Portugal', 'Spain',
       'Ireland', 'New Caledonia', 'Solomon Is.', 'New Zealand',
       'Australia', 'Sri Lanka', 'China', 'Taiwan', 'Italy', 'Denmark',
       'United Kingdom', 'Iceland', 'Azerbaijan', 'Georgia',
       'Philippines', 'Malaysia', 'Brunei', 'Slovenia', 'Finland',
       'Slovakia', 'Czechia', 'Eritrea', 'Japan', 'Paraguay', 'Yemen',
       'Saudi Arabia', 'Antarctica', 'N. Cyprus', 'Cyprus', 'Morocco',
       'Egypt', 'Libya', 'Ethiopia', 'Djibouti', 'Somaliland', 'Uganda',
       'Rwanda', 'Bosnia and Herz.', 'North Macedonia', 'Serbia',
       'Montenegro', 'Kosovo', 'Trinidad and Tobago', 'S. Sudan'],
      dtype=object)
world[world.name.str.contains(country)]
pop_est continent name iso_a3 gdp_md_est geometry
4 328239523.0 North America United States of America USA 21433226 MULTIPOLYGON (((-122.84000 49.00000, -120.00000 49.00000, -117.03121 49.00000, -116.04818 49.00000, -113.00000 49.00000, -110.05000 49.00000, -107.05000 49.00000, -104.04826 48.99986, -100.65000 49.00000, -97.22872 49.00070, -95.15907 49.00000, -95.15609 49.38425, -94.81758 49.38905, -94.64000 48.84000, -94.32914 48.67074, -93.63087 48.60926, -92.61000 48.45000, -91.64000 48.14000, -90.83000 48.27000, -89.60000 48.01000, -89.27292 48.01981, -88.37811 48.30292, -87.43979 47.94000, -86.46199 47.55334, -85.65236 47.22022, -84.87608 46.90008, -84.77924 46.63710, -84.54375 46.53868, -84.60490 4...
country = 'Uganda'
ax = world[world.name.str.contains(country)].plot(figsize=(10,10), color='whitesmoke', linestyle=':', edgecolor='black');ax
loans_data[loans_data.country == country].plot(ax=ax, markersize=2)