Skip to content

Instantly share code, notes, and snippets.

@aloncohen1
Last active October 31, 2022 15:58
Show Gist options
  • Save aloncohen1/4495fc73647edce0cec6f8fe9711c6dd to your computer and use it in GitHub Desktop.
Save aloncohen1/4495fc73647edce0cec6f8fe9711c6dd to your computer and use it in GitHub Desktop.
residence.ipynb
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/",
"height": 206
},
"id": "-ERQmSCVRl4m",
"outputId": "4707e6a1-1276-4725-d94f-9258ac14c650"
},
"outputs": [
{
"data": {
"text/html": [
"\n",
" <div id=\"df-71d06f65-c9df-4587-bf45-04527ffd2b40\">\n",
" <div class=\"colab-df-container\">\n",
" <div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>BlockgroupID</th>\n",
" <th>geometry</th>\n",
" <th>lat</th>\n",
" <th>lng</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>410510005012</td>\n",
" <td>POLYGON ((-122.59120 45.48139, -122.59120 45.4...</td>\n",
" <td>45.481425</td>\n",
" <td>-122.591104</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>410510059001</td>\n",
" <td>POLYGON ((-122.67869 45.49746, -122.67869 45.4...</td>\n",
" <td>45.497409</td>\n",
" <td>-122.678765</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>410510074002</td>\n",
" <td>POLYGON ((-122.60844 45.56566, -122.60844 45.5...</td>\n",
" <td>45.565693</td>\n",
" <td>-122.608380</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>410050216022</td>\n",
" <td>POLYGON ((-122.59890 45.43605, -122.59890 45.4...</td>\n",
" <td>45.435959</td>\n",
" <td>-122.598965</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>410510017012</td>\n",
" <td>POLYGON ((-122.58212 45.52941, -122.58212 45.5...</td>\n",
" <td>45.529375</td>\n",
" <td>-122.582223</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>\n",
" <button class=\"colab-df-convert\" onclick=\"convertToInteractive('df-71d06f65-c9df-4587-bf45-04527ffd2b40')\"\n",
" title=\"Convert this dataframe to an interactive table.\"\n",
" style=\"display:none;\">\n",
" \n",
" <svg xmlns=\"http://www.w3.org/2000/svg\" height=\"24px\"viewBox=\"0 0 24 24\"\n",
" width=\"24px\">\n",
" <path d=\"M0 0h24v24H0V0z\" fill=\"none\"/>\n",
" <path d=\"M18.56 5.44l.94 2.06.94-2.06 2.06-.94-2.06-.94-.94-2.06-.94 2.06-2.06.94zm-11 1L8.5 8.5l.94-2.06 2.06-.94-2.06-.94L8.5 2.5l-.94 2.06-2.06.94zm10 10l.94 2.06.94-2.06 2.06-.94-2.06-.94-.94-2.06-.94 2.06-2.06.94z\"/><path d=\"M17.41 7.96l-1.37-1.37c-.4-.4-.92-.59-1.43-.59-.52 0-1.04.2-1.43.59L10.3 9.45l-7.72 7.72c-.78.78-.78 2.05 0 2.83L4 21.41c.39.39.9.59 1.41.59.51 0 1.02-.2 1.41-.59l7.78-7.78 2.81-2.81c.8-.78.8-2.07 0-2.86zM5.41 20L4 18.59l7.72-7.72 1.47 1.35L5.41 20z\"/>\n",
" </svg>\n",
" </button>\n",
" \n",
" <style>\n",
" .colab-df-container {\n",
" display:flex;\n",
" flex-wrap:wrap;\n",
" gap: 12px;\n",
" }\n",
"\n",
" .colab-df-convert {\n",
" background-color: #E8F0FE;\n",
" border: none;\n",
" border-radius: 50%;\n",
" cursor: pointer;\n",
" display: none;\n",
" fill: #1967D2;\n",
" height: 32px;\n",
" padding: 0 0 0 0;\n",
" width: 32px;\n",
" }\n",
"\n",
" .colab-df-convert:hover {\n",
" background-color: #E2EBFA;\n",
" box-shadow: 0px 1px 2px rgba(60, 64, 67, 0.3), 0px 1px 3px 1px rgba(60, 64, 67, 0.15);\n",
" fill: #174EA6;\n",
" }\n",
"\n",
" [theme=dark] .colab-df-convert {\n",
" background-color: #3B4455;\n",
" fill: #D2E3FC;\n",
" }\n",
"\n",
" [theme=dark] .colab-df-convert:hover {\n",
" background-color: #434B5C;\n",
" box-shadow: 0px 1px 3px 1px rgba(0, 0, 0, 0.15);\n",
" filter: drop-shadow(0px 1px 2px rgba(0, 0, 0, 0.3));\n",
" fill: #FFFFFF;\n",
" }\n",
" </style>\n",
"\n",
" <script>\n",
" const buttonEl =\n",
" document.querySelector('#df-71d06f65-c9df-4587-bf45-04527ffd2b40 button.colab-df-convert');\n",
" buttonEl.style.display =\n",
" google.colab.kernel.accessAllowed ? 'block' : 'none';\n",
"\n",
" async function convertToInteractive(key) {\n",
" const element = document.querySelector('#df-71d06f65-c9df-4587-bf45-04527ffd2b40');\n",
" const dataTable =\n",
" await google.colab.kernel.invokeFunction('convertToInteractive',\n",
" [key], {});\n",
" if (!dataTable) return;\n",
"\n",
" const docLinkHtml = 'Like what you see? Visit the ' +\n",
" '<a target=\"_blank\" href=https://colab.research.google.com/notebooks/data_table.ipynb>data table notebook</a>'\n",
" + ' to learn more about interactive tables.';\n",
" element.innerHTML = '';\n",
" dataTable['output_type'] = 'display_data';\n",
" await google.colab.output.renderOutput(dataTable, element);\n",
" const docLink = document.createElement('div');\n",
" docLink.innerHTML = docLinkHtml;\n",
" element.appendChild(docLink);\n",
" }\n",
" </script>\n",
" </div>\n",
" </div>\n",
" "
],
"text/plain": [
" BlockgroupID geometry lat \\\n",
"0 410510005012 POLYGON ((-122.59120 45.48139, -122.59120 45.4... 45.481425 \n",
"1 410510059001 POLYGON ((-122.67869 45.49746, -122.67869 45.4... 45.497409 \n",
"2 410510074002 POLYGON ((-122.60844 45.56566, -122.60844 45.5... 45.565693 \n",
"3 410050216022 POLYGON ((-122.59890 45.43605, -122.59890 45.4... 45.435959 \n",
"4 410510017012 POLYGON ((-122.58212 45.52941, -122.58212 45.5... 45.529375 \n",
"\n",
" lng \n",
"0 -122.591104 \n",
"1 -122.678765 \n",
"2 -122.608380 \n",
"3 -122.598965 \n",
"4 -122.582223 "
]
},
"execution_count": 11,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"import geopandas as gpd\n",
"\n",
"ARCGIS_REST_URL = 'https://services.arcgis.com/P3ePLMYs2RVChkJx/ArcGIS/rest/services/MSBFP2/FeatureServer/0/query?f=json&returnGeometry=true&spatialRel=esriSpatialRelIntersects&geometry={\"ymax\":%s,\"ymin\":%s,\"xmax\":%s,\"xmin\":%s,\"spatialReference\":{\"wkid\":4326}}&geometryType=esriGeometryEnvelope&outSR=4326'\n",
"\n",
"residence_df = gpd.read_file(ARCGIS_REST_URL % bbox)\n",
"residence_df['lat'] = residence_df['geometry'].centroid.y\n",
"residence_df['lng'] = residence_df['geometry'].centroid.x\n",
"residence_df.head()"
]
}
],
"metadata": {
"colab": {
"collapsed_sections": [],
"provenance": []
},
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.6"
}
},
"nbformat": 4,
"nbformat_minor": 1
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment