[{"data":1,"prerenderedAt":10265},["ShallowReactive",2],{"list-tasks":3},[4,2747,4337,6323,8559],{"id":5,"title":6,"body":7,"description":2740,"extension":2741,"meta":2742,"navigation":125,"path":2743,"seo":2744,"stem":2745,"__hash__":2746},"content\u002Ftasks\u002Ffix-invalid-geometries-python.md","How to Fix Invalid Geometries in Python (GeoPandas)",{"type":8,"value":9,"toc":2696},"minimark",[10,15,19,22,44,47,68,71,75,78,381,392,396,401,404,501,504,532,538,542,548,661,664,703,706,710,717,826,829,846,849,855,861,876,885,888,997,1000,1099,1102,1108,1117,1227,1230,1271,1274,1278,1281,1402,1405,1432,1435,1533,1543,1547,1550,1658,1664,1668,1671,1706,1709,1746,1749,1773,1779,1783,1787,1931,1935,2077,2083,2255,2259,2354,2358,2480,2484,2487,2490,2500,2503,2524,2527,2530,2544,2550,2554,2560,2566,2570,2576,2580,2583,2589,2595,2599,2602,2606,2609,2613,2621,2624,2638,2644,2648,2652,2660,2667,2675,2682,2685,2689,2692],[11,12,14],"h2",{"id":13},"problem-statement","Problem statement",[16,17,18],"p",{},"A common GIS data problem is a vector layer that loads successfully but fails during later processing because some features have invalid geometry.",[16,20,21],{},"This usually shows up when you try to run:",[23,24,25,29,32,35,38,41],"ul",{},[26,27,28],"li",{},"overlays",[26,30,31],{},"spatial joins",[26,33,34],{},"dissolves",[26,36,37],{},"clipping",[26,39,40],{},"exports to file",[26,42,43],{},"imports into PostGIS or another database",[16,45,46],{},"Typical signs include:",[23,48,49,56,59,62,65],{},[26,50,51,55],{},[52,53,54],"code",{},"TopologyException"," errors",[26,57,58],{},"self-intersecting polygons",[26,60,61],{},"empty or broken output",[26,63,64],{},"failed writes to shapefile or GeoJSON",[26,66,67],{},"unexpected spatial operation results",[16,69,70],{},"If you are working with a shapefile or GeoJSON in GeoPandas, the practical fix is to detect invalid features, inspect the reason, repair them, and verify the result before continuing.",[11,72,74],{"id":73},"quick-answer","Quick answer",[16,76,77],{},"The shortest reliable workflow to fix invalid geometries in GeoPandas is:",[79,80,85],"pre",{"className":81,"code":82,"language":83,"meta":84,"style":84},"language-python shiki shiki-themes material-theme-lighter github-light github-dark","import geopandas as gpd\nfrom shapely import make_valid\n\ngdf = gpd.read_file(\"data\u002Fparcels.shp\")\n\ninvalid_mask = ~gdf.geometry.is_valid\ngdf.loc[invalid_mask, \"geometry\"] = gdf.loc[invalid_mask, \"geometry\"].apply(make_valid)\n\ngdf = gdf[gdf.geometry.notna()]\ngdf = gdf[~gdf.geometry.is_empty]\ngdf = gdf[gdf.geometry.is_valid]\n\ngdf.to_file(\"data\u002Fparcels_cleaned.gpkg\", driver=\"GPKG\")\n","python","",[52,86,87,106,120,127,164,169,194,258,263,288,316,340,345],{"__ignoreMap":84},[88,89,92,96,100,103],"span",{"class":90,"line":91},"line",1,[88,93,95],{"class":94},"sVHd0","import",[88,97,99],{"class":98},"su5hD"," geopandas ",[88,101,102],{"class":94},"as",[88,104,105],{"class":98}," gpd\n",[88,107,109,112,115,117],{"class":90,"line":108},2,[88,110,111],{"class":94},"from",[88,113,114],{"class":98}," shapely ",[88,116,95],{"class":94},[88,118,119],{"class":98}," make_valid\n",[88,121,123],{"class":90,"line":122},3,[88,124,126],{"emptyLinePlaceholder":125},true,"\n",[88,128,130,133,137,140,144,148,151,155,159,161],{"class":90,"line":129},4,[88,131,132],{"class":98},"gdf ",[88,134,136],{"class":135},"smGrS","=",[88,138,139],{"class":98}," gpd",[88,141,143],{"class":142},"sP7_E",".",[88,145,147],{"class":146},"slqww","read_file",[88,149,150],{"class":142},"(",[88,152,154],{"class":153},"sjJ54","\"",[88,156,158],{"class":157},"s_sjI","data\u002Fparcels.shp",[88,160,154],{"class":153},[88,162,163],{"class":142},")\n",[88,165,167],{"class":90,"line":166},5,[88,168,126],{"emptyLinePlaceholder":125},[88,170,172,175,177,180,183,185,189,191],{"class":90,"line":171},6,[88,173,174],{"class":98},"invalid_mask ",[88,176,136],{"class":135},[88,178,179],{"class":135}," ~",[88,181,182],{"class":98},"gdf",[88,184,143],{"class":142},[88,186,188],{"class":187},"skxfh","geometry",[88,190,143],{"class":142},[88,192,193],{"class":187},"is_valid\n",[88,195,197,199,201,204,207,210,213,216,218,220,223,226,229,231,233,235,237,239,241,243,245,248,251,253,256],{"class":90,"line":196},7,[88,198,182],{"class":98},[88,200,143],{"class":142},[88,202,203],{"class":187},"loc",[88,205,206],{"class":142},"[",[88,208,209],{"class":187},"invalid_mask",[88,211,212],{"class":142},",",[88,214,215],{"class":153}," \"",[88,217,188],{"class":157},[88,219,154],{"class":153},[88,221,222],{"class":142},"]",[88,224,225],{"class":135}," =",[88,227,228],{"class":98}," gdf",[88,230,143],{"class":142},[88,232,203],{"class":187},[88,234,206],{"class":142},[88,236,209],{"class":187},[88,238,212],{"class":142},[88,240,215],{"class":153},[88,242,188],{"class":157},[88,244,154],{"class":153},[88,246,247],{"class":142},"].",[88,249,250],{"class":146},"apply",[88,252,150],{"class":142},[88,254,255],{"class":146},"make_valid",[88,257,163],{"class":142},[88,259,261],{"class":90,"line":260},8,[88,262,126],{"emptyLinePlaceholder":125},[88,264,266,268,270,272,274,276,278,280,282,285],{"class":90,"line":265},9,[88,267,132],{"class":98},[88,269,136],{"class":135},[88,271,228],{"class":98},[88,273,206],{"class":142},[88,275,182],{"class":98},[88,277,143],{"class":142},[88,279,188],{"class":187},[88,281,143],{"class":142},[88,283,284],{"class":146},"notna",[88,286,287],{"class":142},"()]\n",[88,289,291,293,295,297,299,302,304,306,308,310,313],{"class":90,"line":290},10,[88,292,132],{"class":98},[88,294,136],{"class":135},[88,296,228],{"class":98},[88,298,206],{"class":142},[88,300,301],{"class":135},"~",[88,303,182],{"class":98},[88,305,143],{"class":142},[88,307,188],{"class":187},[88,309,143],{"class":142},[88,311,312],{"class":187},"is_empty",[88,314,315],{"class":142},"]\n",[88,317,319,321,323,325,327,329,331,333,335,338],{"class":90,"line":318},11,[88,320,132],{"class":98},[88,322,136],{"class":135},[88,324,228],{"class":98},[88,326,206],{"class":142},[88,328,182],{"class":98},[88,330,143],{"class":142},[88,332,188],{"class":187},[88,334,143],{"class":142},[88,336,337],{"class":187},"is_valid",[88,339,315],{"class":142},[88,341,343],{"class":90,"line":342},12,[88,344,126],{"emptyLinePlaceholder":125},[88,346,348,350,352,355,357,359,362,364,366,370,372,374,377,379],{"class":90,"line":347},13,[88,349,182],{"class":98},[88,351,143],{"class":142},[88,353,354],{"class":146},"to_file",[88,356,150],{"class":142},[88,358,154],{"class":153},[88,360,361],{"class":157},"data\u002Fparcels_cleaned.gpkg",[88,363,154],{"class":153},[88,365,212],{"class":142},[88,367,369],{"class":368},"s99_P"," driver",[88,371,136],{"class":135},[88,373,154],{"class":153},[88,375,376],{"class":157},"GPKG",[88,378,154],{"class":153},[88,380,163],{"class":142},[16,382,383,384,387,388,391],{},"Use ",[52,385,386],{},"make_valid()"," first. Use ",[52,389,390],{},"buffer(0)"," only as a fallback for simple polygon issues. Always re-check validity before saving.",[11,393,395],{"id":394},"step-by-step-solution","Step-by-step solution",[397,398,400],"h3",{"id":399},"load-the-vector-dataset-into-geopandas","Load the vector dataset into GeoPandas",[16,402,403],{},"Start by reading the source file into a GeoDataFrame.",[79,405,407],{"className":81,"code":406,"language":83,"meta":84,"style":84},"import geopandas as gpd\n\ngdf = gpd.read_file(\"data\u002Fparcels.shp\")\n\nprint(gdf.crs)\nprint(gdf.geometry.name)\nprint(len(gdf))\n",[52,408,409,419,423,445,449,466,485],{"__ignoreMap":84},[88,410,411,413,415,417],{"class":90,"line":91},[88,412,95],{"class":94},[88,414,99],{"class":98},[88,416,102],{"class":94},[88,418,105],{"class":98},[88,420,421],{"class":90,"line":108},[88,422,126],{"emptyLinePlaceholder":125},[88,424,425,427,429,431,433,435,437,439,441,443],{"class":90,"line":122},[88,426,132],{"class":98},[88,428,136],{"class":135},[88,430,139],{"class":98},[88,432,143],{"class":142},[88,434,147],{"class":146},[88,436,150],{"class":142},[88,438,154],{"class":153},[88,440,158],{"class":157},[88,442,154],{"class":153},[88,444,163],{"class":142},[88,446,447],{"class":90,"line":129},[88,448,126],{"emptyLinePlaceholder":125},[88,450,451,455,457,459,461,464],{"class":90,"line":166},[88,452,454],{"class":453},"sptTA","print",[88,456,150],{"class":142},[88,458,182],{"class":146},[88,460,143],{"class":142},[88,462,463],{"class":187},"crs",[88,465,163],{"class":142},[88,467,468,470,472,474,476,478,480,483],{"class":90,"line":171},[88,469,454],{"class":453},[88,471,150],{"class":142},[88,473,182],{"class":146},[88,475,143],{"class":142},[88,477,188],{"class":187},[88,479,143],{"class":142},[88,481,482],{"class":187},"name",[88,484,163],{"class":142},[88,486,487,489,491,494,496,498],{"class":90,"line":196},[88,488,454],{"class":453},[88,490,150],{"class":142},[88,492,493],{"class":453},"len",[88,495,150],{"class":142},[88,497,182],{"class":146},[88,499,500],{"class":142},"))\n",[16,502,503],{},"This works the same way for GeoJSON:",[79,505,507],{"className":81,"code":506,"language":83,"meta":84,"style":84},"gdf = gpd.read_file(\"data\u002Fparcels.geojson\")\n",[52,508,509],{"__ignoreMap":84},[88,510,511,513,515,517,519,521,523,525,528,530],{"class":90,"line":91},[88,512,132],{"class":98},[88,514,136],{"class":135},[88,516,139],{"class":98},[88,518,143],{"class":142},[88,520,147],{"class":146},[88,522,150],{"class":142},[88,524,154],{"class":153},[88,526,527],{"class":157},"data\u002Fparcels.geojson",[88,529,154],{"class":153},[88,531,163],{"class":142},[16,533,534,535,143],{},"If you plan to compare or combine this layer with others later, keep the CRS unchanged or reproject explicitly with ",[52,536,537],{},"to_crs()",[397,539,541],{"id":540},"find-invalid-geometries","Find invalid geometries",[16,543,383,544,547],{},[52,545,546],{},".is_valid"," on the geometry column to identify invalid features.",[79,549,551],{"className":81,"code":550,"language":83,"meta":84,"style":84},"gdf[\"is_valid\"] = gdf.geometry.is_valid\n\ninvalid_gdf = gdf[~gdf[\"is_valid\"]]\n\nprint(\"Total features:\", len(gdf))\nprint(\"Invalid features:\", len(invalid_gdf))\n",[52,552,553,579,583,609,613,637],{"__ignoreMap":84},[88,554,555,557,559,561,563,565,567,569,571,573,575,577],{"class":90,"line":91},[88,556,182],{"class":98},[88,558,206],{"class":142},[88,560,154],{"class":153},[88,562,337],{"class":157},[88,564,154],{"class":153},[88,566,222],{"class":142},[88,568,225],{"class":135},[88,570,228],{"class":98},[88,572,143],{"class":142},[88,574,188],{"class":187},[88,576,143],{"class":142},[88,578,193],{"class":187},[88,580,581],{"class":90,"line":108},[88,582,126],{"emptyLinePlaceholder":125},[88,584,585,588,590,592,594,596,598,600,602,604,606],{"class":90,"line":122},[88,586,587],{"class":98},"invalid_gdf ",[88,589,136],{"class":135},[88,591,228],{"class":98},[88,593,206],{"class":142},[88,595,301],{"class":135},[88,597,182],{"class":98},[88,599,206],{"class":142},[88,601,154],{"class":153},[88,603,337],{"class":157},[88,605,154],{"class":153},[88,607,608],{"class":142},"]]\n",[88,610,611],{"class":90,"line":129},[88,612,126],{"emptyLinePlaceholder":125},[88,614,615,617,619,621,624,626,628,631,633,635],{"class":90,"line":166},[88,616,454],{"class":453},[88,618,150],{"class":142},[88,620,154],{"class":153},[88,622,623],{"class":157},"Total features:",[88,625,154],{"class":153},[88,627,212],{"class":142},[88,629,630],{"class":453}," len",[88,632,150],{"class":142},[88,634,182],{"class":146},[88,636,500],{"class":142},[88,638,639,641,643,645,648,650,652,654,656,659],{"class":90,"line":171},[88,640,454],{"class":453},[88,642,150],{"class":142},[88,644,154],{"class":153},[88,646,647],{"class":157},"Invalid features:",[88,649,154],{"class":153},[88,651,212],{"class":142},[88,653,630],{"class":453},[88,655,150],{"class":142},[88,657,658],{"class":146},"invalid_gdf",[88,660,500],{"class":142},[16,662,663],{},"If you only want the bad rows for review:",[79,665,667],{"className":81,"code":666,"language":83,"meta":84,"style":84},"print(invalid_gdf[[\"is_valid\", \"geometry\"]].head())\n",[52,668,669],{"__ignoreMap":84},[88,670,671,673,675,677,680,682,684,686,688,690,692,694,697,700],{"class":90,"line":91},[88,672,454],{"class":453},[88,674,150],{"class":142},[88,676,658],{"class":146},[88,678,679],{"class":142},"[[",[88,681,154],{"class":153},[88,683,337],{"class":157},[88,685,154],{"class":153},[88,687,212],{"class":142},[88,689,215],{"class":153},[88,691,188],{"class":157},[88,693,154],{"class":153},[88,695,696],{"class":142},"]].",[88,698,699],{"class":146},"head",[88,701,702],{"class":142},"())\n",[16,704,705],{},"This is usually the first check to run before overlay, dissolve, or export operations.",[397,707,709],{"id":708},"check-why-each-geometry-is-invalid","Check why each geometry is invalid",[16,711,712,713,716],{},"Finding invalid rows is useful, but you often also need the reason. Shapely provides ",[52,714,715],{},"explain_validity()"," for this.",[79,718,720],{"className":81,"code":719,"language":83,"meta":84,"style":84},"from shapely.validation import explain_validity\n\ninvalid_gdf = invalid_gdf.copy()\ninvalid_gdf[\"validity_reason\"] = invalid_gdf.geometry.apply(explain_validity)\n\nprint(invalid_gdf[[\"validity_reason\"]].head(10))\n",[52,721,722,739,743,760,794,798],{"__ignoreMap":84},[88,723,724,726,729,731,734,736],{"class":90,"line":91},[88,725,111],{"class":94},[88,727,728],{"class":98}," shapely",[88,730,143],{"class":142},[88,732,733],{"class":98},"validation ",[88,735,95],{"class":94},[88,737,738],{"class":98}," explain_validity\n",[88,740,741],{"class":90,"line":108},[88,742,126],{"emptyLinePlaceholder":125},[88,744,745,747,749,752,754,757],{"class":90,"line":122},[88,746,587],{"class":98},[88,748,136],{"class":135},[88,750,751],{"class":98}," invalid_gdf",[88,753,143],{"class":142},[88,755,756],{"class":146},"copy",[88,758,759],{"class":142},"()\n",[88,761,762,764,766,768,771,773,775,777,779,781,783,785,787,789,792],{"class":90,"line":129},[88,763,658],{"class":98},[88,765,206],{"class":142},[88,767,154],{"class":153},[88,769,770],{"class":157},"validity_reason",[88,772,154],{"class":153},[88,774,222],{"class":142},[88,776,225],{"class":135},[88,778,751],{"class":98},[88,780,143],{"class":142},[88,782,188],{"class":187},[88,784,143],{"class":142},[88,786,250],{"class":146},[88,788,150],{"class":142},[88,790,791],{"class":146},"explain_validity",[88,793,163],{"class":142},[88,795,796],{"class":90,"line":166},[88,797,126],{"emptyLinePlaceholder":125},[88,799,800,802,804,806,808,810,812,814,816,818,820,824],{"class":90,"line":171},[88,801,454],{"class":453},[88,803,150],{"class":142},[88,805,658],{"class":146},[88,807,679],{"class":142},[88,809,154],{"class":153},[88,811,770],{"class":157},[88,813,154],{"class":153},[88,815,696],{"class":142},[88,817,699],{"class":146},[88,819,150],{"class":142},[88,821,823],{"class":822},"srdBf","10",[88,825,500],{"class":142},[16,827,828],{},"Typical messages include:",[23,830,831,836,841],{},[26,832,833],{},[52,834,835],{},"Self-intersection",[26,837,838],{},[52,839,840],{},"Ring Self-intersection",[26,842,843],{},[52,844,845],{},"Too few points in geometry component",[16,847,848],{},"This helps you understand whether you are dealing with a few isolated errors or a broader data-quality problem.",[397,850,852,853],{"id":851},"repair-geometries-with-make_valid","Repair geometries with ",[52,854,386],{},[16,856,857,858,860],{},"The preferred repair method is ",[52,859,386],{}," from Shapely.",[79,862,864],{"className":81,"code":863,"language":83,"meta":84,"style":84},"from shapely import make_valid\n",[52,865,866],{"__ignoreMap":84},[88,867,868,870,872,874],{"class":90,"line":91},[88,869,111],{"class":94},[88,871,114],{"class":98},[88,873,95],{"class":94},[88,875,119],{"class":98},[16,877,878,879,881,882,884],{},"This requires a modern Shapely version that provides ",[52,880,386],{},". In older environments, use ",[52,883,390],{}," only as a limited fallback and consider upgrading Shapely.",[16,886,887],{},"Apply it only to invalid rows:",[79,889,891],{"className":81,"code":890,"language":83,"meta":84,"style":84},"gdf_repaired = gdf.copy()\n\ninvalid_mask = ~gdf_repaired.geometry.is_valid\n\ngdf_repaired.loc[invalid_mask, \"geometry\"] = (\n    gdf_repaired.loc[invalid_mask, \"geometry\"].apply(make_valid)\n)\n",[52,892,893,908,912,931,935,962,993],{"__ignoreMap":84},[88,894,895,898,900,902,904,906],{"class":90,"line":91},[88,896,897],{"class":98},"gdf_repaired ",[88,899,136],{"class":135},[88,901,228],{"class":98},[88,903,143],{"class":142},[88,905,756],{"class":146},[88,907,759],{"class":142},[88,909,910],{"class":90,"line":108},[88,911,126],{"emptyLinePlaceholder":125},[88,913,914,916,918,920,923,925,927,929],{"class":90,"line":122},[88,915,174],{"class":98},[88,917,136],{"class":135},[88,919,179],{"class":135},[88,921,922],{"class":98},"gdf_repaired",[88,924,143],{"class":142},[88,926,188],{"class":187},[88,928,143],{"class":142},[88,930,193],{"class":187},[88,932,933],{"class":90,"line":129},[88,934,126],{"emptyLinePlaceholder":125},[88,936,937,939,941,943,945,947,949,951,953,955,957,959],{"class":90,"line":166},[88,938,922],{"class":98},[88,940,143],{"class":142},[88,942,203],{"class":187},[88,944,206],{"class":142},[88,946,209],{"class":187},[88,948,212],{"class":142},[88,950,215],{"class":153},[88,952,188],{"class":157},[88,954,154],{"class":153},[88,956,222],{"class":142},[88,958,225],{"class":135},[88,960,961],{"class":142}," (\n",[88,963,964,967,969,971,973,975,977,979,981,983,985,987,989,991],{"class":90,"line":171},[88,965,966],{"class":98},"    gdf_repaired",[88,968,143],{"class":142},[88,970,203],{"class":187},[88,972,206],{"class":142},[88,974,209],{"class":187},[88,976,212],{"class":142},[88,978,215],{"class":153},[88,980,188],{"class":157},[88,982,154],{"class":153},[88,984,247],{"class":142},[88,986,250],{"class":146},[88,988,150],{"class":142},[88,990,255],{"class":146},[88,992,163],{"class":142},[88,994,995],{"class":90,"line":196},[88,996,163],{"class":142},[16,998,999],{},"Then check the result:",[79,1001,1003],{"className":81,"code":1002,"language":83,"meta":84,"style":84},"gdf_repaired[\"is_valid_after\"] = gdf_repaired.geometry.is_valid\n\nprint(\"Still invalid:\", (~gdf_repaired[\"is_valid_after\"]).sum())\nprint(gdf_repaired.geometry.geom_type.value_counts())\n",[52,1004,1005,1033,1037,1075],{"__ignoreMap":84},[88,1006,1007,1009,1011,1013,1016,1018,1020,1022,1025,1027,1029,1031],{"class":90,"line":91},[88,1008,922],{"class":98},[88,1010,206],{"class":142},[88,1012,154],{"class":153},[88,1014,1015],{"class":157},"is_valid_after",[88,1017,154],{"class":153},[88,1019,222],{"class":142},[88,1021,225],{"class":135},[88,1023,1024],{"class":98}," gdf_repaired",[88,1026,143],{"class":142},[88,1028,188],{"class":187},[88,1030,143],{"class":142},[88,1032,193],{"class":187},[88,1034,1035],{"class":90,"line":108},[88,1036,126],{"emptyLinePlaceholder":125},[88,1038,1039,1041,1043,1045,1048,1050,1052,1055,1057,1059,1061,1063,1065,1067,1070,1073],{"class":90,"line":122},[88,1040,454],{"class":453},[88,1042,150],{"class":142},[88,1044,154],{"class":153},[88,1046,1047],{"class":157},"Still invalid:",[88,1049,154],{"class":153},[88,1051,212],{"class":142},[88,1053,1054],{"class":142}," (",[88,1056,301],{"class":135},[88,1058,922],{"class":146},[88,1060,206],{"class":142},[88,1062,154],{"class":153},[88,1064,1015],{"class":157},[88,1066,154],{"class":153},[88,1068,1069],{"class":142},"]).",[88,1071,1072],{"class":146},"sum",[88,1074,702],{"class":142},[88,1076,1077,1079,1081,1083,1085,1087,1089,1092,1094,1097],{"class":90,"line":129},[88,1078,454],{"class":453},[88,1080,150],{"class":142},[88,1082,922],{"class":146},[88,1084,143],{"class":142},[88,1086,188],{"class":187},[88,1088,143],{"class":142},[88,1090,1091],{"class":187},"geom_type",[88,1093,143],{"class":142},[88,1095,1096],{"class":146},"value_counts",[88,1098,702],{"class":142},[16,1100,1101],{},"This is the best default option in current GeoPandas and Shapely workflows.",[397,1103,383,1105,1107],{"id":1104},"use-buffer0-as-a-fallback-for-simple-polygon-issues",[52,1106,390],{}," as a fallback for simple polygon issues",[16,1109,1110,1111,1113,1114,1116],{},"If ",[52,1112,386],{}," is not available in your environment, or if you are testing a simple self-intersection fix, ",[52,1115,390],{}," can help.",[79,1118,1120],{"className":81,"code":1119,"language":83,"meta":84,"style":84},"gdf_buffered = gdf.copy()\n\ninvalid_mask = ~gdf_buffered.geometry.is_valid\n\ngdf_buffered.loc[invalid_mask, \"geometry\"] = (\n    gdf_buffered.loc[invalid_mask, \"geometry\"].buffer(0)\n)\n",[52,1121,1122,1137,1141,1160,1164,1190,1223],{"__ignoreMap":84},[88,1123,1124,1127,1129,1131,1133,1135],{"class":90,"line":91},[88,1125,1126],{"class":98},"gdf_buffered ",[88,1128,136],{"class":135},[88,1130,228],{"class":98},[88,1132,143],{"class":142},[88,1134,756],{"class":146},[88,1136,759],{"class":142},[88,1138,1139],{"class":90,"line":108},[88,1140,126],{"emptyLinePlaceholder":125},[88,1142,1143,1145,1147,1149,1152,1154,1156,1158],{"class":90,"line":122},[88,1144,174],{"class":98},[88,1146,136],{"class":135},[88,1148,179],{"class":135},[88,1150,1151],{"class":98},"gdf_buffered",[88,1153,143],{"class":142},[88,1155,188],{"class":187},[88,1157,143],{"class":142},[88,1159,193],{"class":187},[88,1161,1162],{"class":90,"line":129},[88,1163,126],{"emptyLinePlaceholder":125},[88,1165,1166,1168,1170,1172,1174,1176,1178,1180,1182,1184,1186,1188],{"class":90,"line":166},[88,1167,1151],{"class":98},[88,1169,143],{"class":142},[88,1171,203],{"class":187},[88,1173,206],{"class":142},[88,1175,209],{"class":187},[88,1177,212],{"class":142},[88,1179,215],{"class":153},[88,1181,188],{"class":157},[88,1183,154],{"class":153},[88,1185,222],{"class":142},[88,1187,225],{"class":135},[88,1189,961],{"class":142},[88,1191,1192,1195,1197,1199,1201,1203,1205,1207,1209,1211,1213,1216,1218,1221],{"class":90,"line":171},[88,1193,1194],{"class":98},"    gdf_buffered",[88,1196,143],{"class":142},[88,1198,203],{"class":187},[88,1200,206],{"class":142},[88,1202,209],{"class":187},[88,1204,212],{"class":142},[88,1206,215],{"class":153},[88,1208,188],{"class":157},[88,1210,154],{"class":153},[88,1212,247],{"class":142},[88,1214,1215],{"class":146},"buffer",[88,1217,150],{"class":142},[88,1219,1220],{"class":822},"0",[88,1222,163],{"class":142},[88,1224,1225],{"class":90,"line":196},[88,1226,163],{"class":142},[16,1228,1229],{},"Re-check validity:",[79,1231,1233],{"className":81,"code":1232,"language":83,"meta":84,"style":84},"print(\"Still invalid after buffer(0):\", (~gdf_buffered.geometry.is_valid).sum())\n",[52,1234,1235],{"__ignoreMap":84},[88,1236,1237,1239,1241,1243,1246,1248,1250,1252,1254,1256,1258,1260,1262,1264,1267,1269],{"class":90,"line":91},[88,1238,454],{"class":453},[88,1240,150],{"class":142},[88,1242,154],{"class":153},[88,1244,1245],{"class":157},"Still invalid after buffer(0):",[88,1247,154],{"class":153},[88,1249,212],{"class":142},[88,1251,1054],{"class":142},[88,1253,301],{"class":135},[88,1255,1151],{"class":146},[88,1257,143],{"class":142},[88,1259,188],{"class":187},[88,1261,143],{"class":142},[88,1263,337],{"class":187},[88,1265,1266],{"class":142},").",[88,1268,1072],{"class":146},[88,1270,702],{"class":142},[16,1272,1273],{},"Use this carefully. It can change geometry shape or remove small artifacts. It is not the best default repair method.",[397,1275,1277],{"id":1276},"remove-empty-or-still-invalid-results","Remove empty or still-invalid results",[16,1279,1280],{},"Some repaired geometries may become empty, null, or remain invalid.",[79,1282,1284],{"className":81,"code":1283,"language":83,"meta":84,"style":84},"cleaned = gdf_repaired.copy()\n\ncleaned = cleaned[cleaned.geometry.notna()]\ncleaned = cleaned[~cleaned.geometry.is_empty]\ncleaned = cleaned[cleaned.geometry.is_valid]\n\nprint(\"Remaining features:\", len(cleaned))\n",[52,1285,1286,1301,1305,1329,1353,1375,1379],{"__ignoreMap":84},[88,1287,1288,1291,1293,1295,1297,1299],{"class":90,"line":91},[88,1289,1290],{"class":98},"cleaned ",[88,1292,136],{"class":135},[88,1294,1024],{"class":98},[88,1296,143],{"class":142},[88,1298,756],{"class":146},[88,1300,759],{"class":142},[88,1302,1303],{"class":90,"line":108},[88,1304,126],{"emptyLinePlaceholder":125},[88,1306,1307,1309,1311,1314,1316,1319,1321,1323,1325,1327],{"class":90,"line":122},[88,1308,1290],{"class":98},[88,1310,136],{"class":135},[88,1312,1313],{"class":98}," cleaned",[88,1315,206],{"class":142},[88,1317,1318],{"class":98},"cleaned",[88,1320,143],{"class":142},[88,1322,188],{"class":187},[88,1324,143],{"class":142},[88,1326,284],{"class":146},[88,1328,287],{"class":142},[88,1330,1331,1333,1335,1337,1339,1341,1343,1345,1347,1349,1351],{"class":90,"line":129},[88,1332,1290],{"class":98},[88,1334,136],{"class":135},[88,1336,1313],{"class":98},[88,1338,206],{"class":142},[88,1340,301],{"class":135},[88,1342,1318],{"class":98},[88,1344,143],{"class":142},[88,1346,188],{"class":187},[88,1348,143],{"class":142},[88,1350,312],{"class":187},[88,1352,315],{"class":142},[88,1354,1355,1357,1359,1361,1363,1365,1367,1369,1371,1373],{"class":90,"line":166},[88,1356,1290],{"class":98},[88,1358,136],{"class":135},[88,1360,1313],{"class":98},[88,1362,206],{"class":142},[88,1364,1318],{"class":98},[88,1366,143],{"class":142},[88,1368,188],{"class":187},[88,1370,143],{"class":142},[88,1372,337],{"class":187},[88,1374,315],{"class":142},[88,1376,1377],{"class":90,"line":171},[88,1378,126],{"emptyLinePlaceholder":125},[88,1380,1381,1383,1385,1387,1390,1392,1394,1396,1398,1400],{"class":90,"line":196},[88,1382,454],{"class":453},[88,1384,150],{"class":142},[88,1386,154],{"class":153},[88,1388,1389],{"class":157},"Remaining features:",[88,1391,154],{"class":153},[88,1393,212],{"class":142},[88,1395,630],{"class":453},[88,1397,150],{"class":142},[88,1399,1318],{"class":146},[88,1401,500],{"class":142},[16,1403,1404],{},"If downstream tools require polygon-only output, inspect geometry types after repair:",[79,1406,1408],{"className":81,"code":1407,"language":83,"meta":84,"style":84},"print(cleaned.geometry.geom_type.value_counts())\n",[52,1409,1410],{"__ignoreMap":84},[88,1411,1412,1414,1416,1418,1420,1422,1424,1426,1428,1430],{"class":90,"line":91},[88,1413,454],{"class":453},[88,1415,150],{"class":142},[88,1417,1318],{"class":146},[88,1419,143],{"class":142},[88,1421,188],{"class":187},[88,1423,143],{"class":142},[88,1425,1091],{"class":187},[88,1427,143],{"class":142},[88,1429,1096],{"class":146},[88,1431,702],{"class":142},[16,1433,1434],{},"A simple polygon-only filter is:",[79,1436,1438],{"className":81,"code":1437,"language":83,"meta":84,"style":84},"polygon_types = [\"Polygon\", \"MultiPolygon\"]\ncleaned_polygons = cleaned[cleaned.geometry.geom_type.isin(polygon_types)].copy()\n\nprint(cleaned_polygons.geometry.geom_type.value_counts())\n",[52,1439,1440,1468,1506,1510],{"__ignoreMap":84},[88,1441,1442,1445,1447,1450,1452,1455,1457,1459,1461,1464,1466],{"class":90,"line":91},[88,1443,1444],{"class":98},"polygon_types ",[88,1446,136],{"class":135},[88,1448,1449],{"class":142}," [",[88,1451,154],{"class":153},[88,1453,1454],{"class":157},"Polygon",[88,1456,154],{"class":153},[88,1458,212],{"class":142},[88,1460,215],{"class":153},[88,1462,1463],{"class":157},"MultiPolygon",[88,1465,154],{"class":153},[88,1467,315],{"class":142},[88,1469,1470,1473,1475,1477,1479,1481,1483,1485,1487,1489,1491,1494,1496,1499,1502,1504],{"class":90,"line":108},[88,1471,1472],{"class":98},"cleaned_polygons ",[88,1474,136],{"class":135},[88,1476,1313],{"class":98},[88,1478,206],{"class":142},[88,1480,1318],{"class":98},[88,1482,143],{"class":142},[88,1484,188],{"class":187},[88,1486,143],{"class":142},[88,1488,1091],{"class":187},[88,1490,143],{"class":142},[88,1492,1493],{"class":146},"isin",[88,1495,150],{"class":142},[88,1497,1498],{"class":146},"polygon_types",[88,1500,1501],{"class":142},")].",[88,1503,756],{"class":146},[88,1505,759],{"class":142},[88,1507,1508],{"class":90,"line":122},[88,1509,126],{"emptyLinePlaceholder":125},[88,1511,1512,1514,1516,1519,1521,1523,1525,1527,1529,1531],{"class":90,"line":129},[88,1513,454],{"class":453},[88,1515,150],{"class":142},[88,1517,1518],{"class":146},"cleaned_polygons",[88,1520,143],{"class":142},[88,1522,188],{"class":187},[88,1524,143],{"class":142},[88,1526,1091],{"class":187},[88,1528,143],{"class":142},[88,1530,1096],{"class":146},[88,1532,702],{"class":142},[16,1534,1535,1536,1538,1539,1542],{},"This is useful when ",[52,1537,386],{}," returns ",[52,1540,1541],{},"GeometryCollection"," or other non-polygon results.",[397,1544,1546],{"id":1545},"verify-repaired-geometries-before-continuing","Verify repaired geometries before continuing",[16,1548,1549],{},"Before running overlay, dissolve, or export steps, confirm the repair worked.",[79,1551,1553],{"className":81,"code":1552,"language":83,"meta":84,"style":84},"print(\"Original feature count:\", len(gdf))\nprint(\"Cleaned feature count:\", len(cleaned))\nprint(\"Invalid after repair:\", (~cleaned.geometry.is_valid).sum())\nprint(cleaned.geometry.geom_type.value_counts())\n",[52,1554,1555,1578,1601,1636],{"__ignoreMap":84},[88,1556,1557,1559,1561,1563,1566,1568,1570,1572,1574,1576],{"class":90,"line":91},[88,1558,454],{"class":453},[88,1560,150],{"class":142},[88,1562,154],{"class":153},[88,1564,1565],{"class":157},"Original feature count:",[88,1567,154],{"class":153},[88,1569,212],{"class":142},[88,1571,630],{"class":453},[88,1573,150],{"class":142},[88,1575,182],{"class":146},[88,1577,500],{"class":142},[88,1579,1580,1582,1584,1586,1589,1591,1593,1595,1597,1599],{"class":90,"line":108},[88,1581,454],{"class":453},[88,1583,150],{"class":142},[88,1585,154],{"class":153},[88,1587,1588],{"class":157},"Cleaned feature count:",[88,1590,154],{"class":153},[88,1592,212],{"class":142},[88,1594,630],{"class":453},[88,1596,150],{"class":142},[88,1598,1318],{"class":146},[88,1600,500],{"class":142},[88,1602,1603,1605,1607,1609,1612,1614,1616,1618,1620,1622,1624,1626,1628,1630,1632,1634],{"class":90,"line":122},[88,1604,454],{"class":453},[88,1606,150],{"class":142},[88,1608,154],{"class":153},[88,1610,1611],{"class":157},"Invalid after repair:",[88,1613,154],{"class":153},[88,1615,212],{"class":142},[88,1617,1054],{"class":142},[88,1619,301],{"class":135},[88,1621,1318],{"class":146},[88,1623,143],{"class":142},[88,1625,188],{"class":187},[88,1627,143],{"class":142},[88,1629,337],{"class":187},[88,1631,1266],{"class":142},[88,1633,1072],{"class":146},[88,1635,702],{"class":142},[88,1637,1638,1640,1642,1644,1646,1648,1650,1652,1654,1656],{"class":90,"line":129},[88,1639,454],{"class":453},[88,1641,150],{"class":142},[88,1643,1318],{"class":146},[88,1645,143],{"class":142},[88,1647,188],{"class":187},[88,1649,143],{"class":142},[88,1651,1091],{"class":187},[88,1653,143],{"class":142},[88,1655,1096],{"class":146},[88,1657,702],{"class":142},[16,1659,1660,1661,1663],{},"This matters because ",[52,1662,386],{}," may split one invalid polygon into multiple valid parts or return a different geometry type.",[397,1665,1667],{"id":1666},"save-the-cleaned-dataset","Save the cleaned dataset",[16,1669,1670],{},"Write the cleaned layer to an output format after checking the geometry types you now have.",[79,1672,1674],{"className":81,"code":1673,"language":83,"meta":84,"style":84},"cleaned.to_file(\"data\u002Fparcels_cleaned.gpkg\", driver=\"GPKG\")\n",[52,1675,1676],{"__ignoreMap":84},[88,1677,1678,1680,1682,1684,1686,1688,1690,1692,1694,1696,1698,1700,1702,1704],{"class":90,"line":91},[88,1679,1318],{"class":98},[88,1681,143],{"class":142},[88,1683,354],{"class":146},[88,1685,150],{"class":142},[88,1687,154],{"class":153},[88,1689,361],{"class":157},[88,1691,154],{"class":153},[88,1693,212],{"class":142},[88,1695,369],{"class":368},[88,1697,136],{"class":135},[88,1699,154],{"class":153},[88,1701,376],{"class":157},[88,1703,154],{"class":153},[88,1705,163],{"class":142},[16,1707,1708],{},"You can also save to GeoJSON:",[79,1710,1712],{"className":81,"code":1711,"language":83,"meta":84,"style":84},"cleaned.to_file(\"data\u002Fparcels_cleaned.geojson\", driver=\"GeoJSON\")\n",[52,1713,1714],{"__ignoreMap":84},[88,1715,1716,1718,1720,1722,1724,1726,1729,1731,1733,1735,1737,1739,1742,1744],{"class":90,"line":91},[88,1717,1318],{"class":98},[88,1719,143],{"class":142},[88,1721,354],{"class":146},[88,1723,150],{"class":142},[88,1725,154],{"class":153},[88,1727,1728],{"class":157},"data\u002Fparcels_cleaned.geojson",[88,1730,154],{"class":153},[88,1732,212],{"class":142},[88,1734,369],{"class":368},[88,1736,136],{"class":135},[88,1738,154],{"class":153},[88,1740,1741],{"class":157},"GeoJSON",[88,1743,154],{"class":153},[88,1745,163],{"class":142},[16,1747,1748],{},"If you save to shapefile, be aware that it is more restrictive:",[79,1750,1752],{"className":81,"code":1751,"language":83,"meta":84,"style":84},"cleaned.to_file(\"data\u002Fparcels_cleaned.shp\")\n",[52,1753,1754],{"__ignoreMap":84},[88,1755,1756,1758,1760,1762,1764,1766,1769,1771],{"class":90,"line":91},[88,1757,1318],{"class":98},[88,1759,143],{"class":142},[88,1761,354],{"class":146},[88,1763,150],{"class":142},[88,1765,154],{"class":153},[88,1767,1768],{"class":157},"data\u002Fparcels_cleaned.shp",[88,1770,154],{"class":153},[88,1772,163],{"class":142},[16,1774,1775,1776,1778],{},"GeoPackage is often the safer choice than shapefile when repaired features become multipart. If repair produces mixed geometry types such as ",[52,1777,1541],{},", inspect and filter geometry types before saving.",[11,1780,1782],{"id":1781},"code-examples","Code examples",[397,1784,1786],{"id":1785},"example-1-detect-invalid-geometries-in-a-shapefile","Example 1: Detect invalid geometries in a shapefile",[79,1788,1790],{"className":81,"code":1789,"language":83,"meta":84,"style":84},"import geopandas as gpd\n\ngdf = gpd.read_file(\"data\u002Fbuildings.shp\")\ngdf[\"is_valid\"] = gdf.geometry.is_valid\n\ninvalid_gdf = gdf[~gdf[\"is_valid\"]]\n\nprint(\"Invalid features:\", len(invalid_gdf))\nprint(invalid_gdf[[\"is_valid\"]].head())\n",[52,1791,1792,1802,1806,1829,1855,1859,1883,1887,1909],{"__ignoreMap":84},[88,1793,1794,1796,1798,1800],{"class":90,"line":91},[88,1795,95],{"class":94},[88,1797,99],{"class":98},[88,1799,102],{"class":94},[88,1801,105],{"class":98},[88,1803,1804],{"class":90,"line":108},[88,1805,126],{"emptyLinePlaceholder":125},[88,1807,1808,1810,1812,1814,1816,1818,1820,1822,1825,1827],{"class":90,"line":122},[88,1809,132],{"class":98},[88,1811,136],{"class":135},[88,1813,139],{"class":98},[88,1815,143],{"class":142},[88,1817,147],{"class":146},[88,1819,150],{"class":142},[88,1821,154],{"class":153},[88,1823,1824],{"class":157},"data\u002Fbuildings.shp",[88,1826,154],{"class":153},[88,1828,163],{"class":142},[88,1830,1831,1833,1835,1837,1839,1841,1843,1845,1847,1849,1851,1853],{"class":90,"line":129},[88,1832,182],{"class":98},[88,1834,206],{"class":142},[88,1836,154],{"class":153},[88,1838,337],{"class":157},[88,1840,154],{"class":153},[88,1842,222],{"class":142},[88,1844,225],{"class":135},[88,1846,228],{"class":98},[88,1848,143],{"class":142},[88,1850,188],{"class":187},[88,1852,143],{"class":142},[88,1854,193],{"class":187},[88,1856,1857],{"class":90,"line":166},[88,1858,126],{"emptyLinePlaceholder":125},[88,1860,1861,1863,1865,1867,1869,1871,1873,1875,1877,1879,1881],{"class":90,"line":171},[88,1862,587],{"class":98},[88,1864,136],{"class":135},[88,1866,228],{"class":98},[88,1868,206],{"class":142},[88,1870,301],{"class":135},[88,1872,182],{"class":98},[88,1874,206],{"class":142},[88,1876,154],{"class":153},[88,1878,337],{"class":157},[88,1880,154],{"class":153},[88,1882,608],{"class":142},[88,1884,1885],{"class":90,"line":196},[88,1886,126],{"emptyLinePlaceholder":125},[88,1888,1889,1891,1893,1895,1897,1899,1901,1903,1905,1907],{"class":90,"line":260},[88,1890,454],{"class":453},[88,1892,150],{"class":142},[88,1894,154],{"class":153},[88,1896,647],{"class":157},[88,1898,154],{"class":153},[88,1900,212],{"class":142},[88,1902,630],{"class":453},[88,1904,150],{"class":142},[88,1906,658],{"class":146},[88,1908,500],{"class":142},[88,1910,1911,1913,1915,1917,1919,1921,1923,1925,1927,1929],{"class":90,"line":265},[88,1912,454],{"class":453},[88,1914,150],{"class":142},[88,1916,658],{"class":146},[88,1918,679],{"class":142},[88,1920,154],{"class":153},[88,1922,337],{"class":157},[88,1924,154],{"class":153},[88,1926,696],{"class":142},[88,1928,699],{"class":146},[88,1930,702],{"class":142},[397,1932,1934],{"id":1933},"example-2-print-validation-reasons-for-bad-features","Example 2: Print validation reasons for bad features",[79,1936,1938],{"className":81,"code":1937,"language":83,"meta":84,"style":84},"from shapely.validation import explain_validity\n\ninvalid_gdf = invalid_gdf.copy()\ninvalid_gdf[\"reason\"] = invalid_gdf.geometry.apply(explain_validity)\n\nfor idx, row in invalid_gdf[[\"reason\"]].head(10).iterrows():\n    print(idx, row[\"reason\"])\n",[52,1939,1940,1954,1958,1972,2005,2009,2051],{"__ignoreMap":84},[88,1941,1942,1944,1946,1948,1950,1952],{"class":90,"line":91},[88,1943,111],{"class":94},[88,1945,728],{"class":98},[88,1947,143],{"class":142},[88,1949,733],{"class":98},[88,1951,95],{"class":94},[88,1953,738],{"class":98},[88,1955,1956],{"class":90,"line":108},[88,1957,126],{"emptyLinePlaceholder":125},[88,1959,1960,1962,1964,1966,1968,1970],{"class":90,"line":122},[88,1961,587],{"class":98},[88,1963,136],{"class":135},[88,1965,751],{"class":98},[88,1967,143],{"class":142},[88,1969,756],{"class":146},[88,1971,759],{"class":142},[88,1973,1974,1976,1978,1980,1983,1985,1987,1989,1991,1993,1995,1997,1999,2001,2003],{"class":90,"line":129},[88,1975,658],{"class":98},[88,1977,206],{"class":142},[88,1979,154],{"class":153},[88,1981,1982],{"class":157},"reason",[88,1984,154],{"class":153},[88,1986,222],{"class":142},[88,1988,225],{"class":135},[88,1990,751],{"class":98},[88,1992,143],{"class":142},[88,1994,188],{"class":187},[88,1996,143],{"class":142},[88,1998,250],{"class":146},[88,2000,150],{"class":142},[88,2002,791],{"class":146},[88,2004,163],{"class":142},[88,2006,2007],{"class":90,"line":166},[88,2008,126],{"emptyLinePlaceholder":125},[88,2010,2011,2014,2017,2019,2022,2025,2027,2029,2031,2033,2035,2037,2039,2041,2043,2045,2048],{"class":90,"line":171},[88,2012,2013],{"class":94},"for",[88,2015,2016],{"class":98}," idx",[88,2018,212],{"class":142},[88,2020,2021],{"class":98}," row ",[88,2023,2024],{"class":94},"in",[88,2026,751],{"class":98},[88,2028,679],{"class":142},[88,2030,154],{"class":153},[88,2032,1982],{"class":157},[88,2034,154],{"class":153},[88,2036,696],{"class":142},[88,2038,699],{"class":146},[88,2040,150],{"class":142},[88,2042,823],{"class":822},[88,2044,1266],{"class":142},[88,2046,2047],{"class":146},"iterrows",[88,2049,2050],{"class":142},"():\n",[88,2052,2053,2056,2058,2061,2063,2066,2068,2070,2072,2074],{"class":90,"line":196},[88,2054,2055],{"class":453},"    print",[88,2057,150],{"class":142},[88,2059,2060],{"class":146},"idx",[88,2062,212],{"class":142},[88,2064,2065],{"class":146}," row",[88,2067,206],{"class":142},[88,2069,154],{"class":153},[88,2071,1982],{"class":157},[88,2073,154],{"class":153},[88,2075,2076],{"class":142},"])\n",[397,2078,2080,2081],{"id":2079},"example-3-repair-geometries-with-make_valid","Example 3: Repair geometries with ",[52,2082,386],{},[79,2084,2086],{"className":81,"code":2085,"language":83,"meta":84,"style":84},"from shapely import make_valid\n\ngdf_fixed = gdf.copy()\nmask = ~gdf_fixed.geometry.is_valid\n\ngdf_fixed.loc[mask, \"geometry\"] = gdf_fixed.loc[mask, \"geometry\"].apply(make_valid)\n\nprint(\"Invalid after repair:\", (~gdf_fixed.geometry.is_valid).sum())\nprint(gdf_fixed.geometry.geom_type.value_counts())\n",[52,2087,2088,2098,2102,2117,2137,2141,2195,2199,2233],{"__ignoreMap":84},[88,2089,2090,2092,2094,2096],{"class":90,"line":91},[88,2091,111],{"class":94},[88,2093,114],{"class":98},[88,2095,95],{"class":94},[88,2097,119],{"class":98},[88,2099,2100],{"class":90,"line":108},[88,2101,126],{"emptyLinePlaceholder":125},[88,2103,2104,2107,2109,2111,2113,2115],{"class":90,"line":122},[88,2105,2106],{"class":98},"gdf_fixed ",[88,2108,136],{"class":135},[88,2110,228],{"class":98},[88,2112,143],{"class":142},[88,2114,756],{"class":146},[88,2116,759],{"class":142},[88,2118,2119,2122,2124,2126,2129,2131,2133,2135],{"class":90,"line":129},[88,2120,2121],{"class":98},"mask ",[88,2123,136],{"class":135},[88,2125,179],{"class":135},[88,2127,2128],{"class":98},"gdf_fixed",[88,2130,143],{"class":142},[88,2132,188],{"class":187},[88,2134,143],{"class":142},[88,2136,193],{"class":187},[88,2138,2139],{"class":90,"line":166},[88,2140,126],{"emptyLinePlaceholder":125},[88,2142,2143,2145,2147,2149,2151,2154,2156,2158,2160,2162,2164,2166,2169,2171,2173,2175,2177,2179,2181,2183,2185,2187,2189,2191,2193],{"class":90,"line":171},[88,2144,2128],{"class":98},[88,2146,143],{"class":142},[88,2148,203],{"class":187},[88,2150,206],{"class":142},[88,2152,2153],{"class":187},"mask",[88,2155,212],{"class":142},[88,2157,215],{"class":153},[88,2159,188],{"class":157},[88,2161,154],{"class":153},[88,2163,222],{"class":142},[88,2165,225],{"class":135},[88,2167,2168],{"class":98}," gdf_fixed",[88,2170,143],{"class":142},[88,2172,203],{"class":187},[88,2174,206],{"class":142},[88,2176,2153],{"class":187},[88,2178,212],{"class":142},[88,2180,215],{"class":153},[88,2182,188],{"class":157},[88,2184,154],{"class":153},[88,2186,247],{"class":142},[88,2188,250],{"class":146},[88,2190,150],{"class":142},[88,2192,255],{"class":146},[88,2194,163],{"class":142},[88,2196,2197],{"class":90,"line":196},[88,2198,126],{"emptyLinePlaceholder":125},[88,2200,2201,2203,2205,2207,2209,2211,2213,2215,2217,2219,2221,2223,2225,2227,2229,2231],{"class":90,"line":260},[88,2202,454],{"class":453},[88,2204,150],{"class":142},[88,2206,154],{"class":153},[88,2208,1611],{"class":157},[88,2210,154],{"class":153},[88,2212,212],{"class":142},[88,2214,1054],{"class":142},[88,2216,301],{"class":135},[88,2218,2128],{"class":146},[88,2220,143],{"class":142},[88,2222,188],{"class":187},[88,2224,143],{"class":142},[88,2226,337],{"class":187},[88,2228,1266],{"class":142},[88,2230,1072],{"class":146},[88,2232,702],{"class":142},[88,2234,2235,2237,2239,2241,2243,2245,2247,2249,2251,2253],{"class":90,"line":265},[88,2236,454],{"class":453},[88,2238,150],{"class":142},[88,2240,2128],{"class":146},[88,2242,143],{"class":142},[88,2244,188],{"class":187},[88,2246,143],{"class":142},[88,2248,1091],{"class":187},[88,2250,143],{"class":142},[88,2252,1096],{"class":146},[88,2254,702],{"class":142},[397,2256,2258],{"id":2257},"example-4-keep-only-polygon-results-after-repair","Example 4: Keep only polygon results after repair",[79,2260,2262],{"className":81,"code":2261,"language":83,"meta":84,"style":84},"polygon_types = [\"Polygon\", \"MultiPolygon\"]\n\ngdf_polygons = gdf_fixed[gdf_fixed.geometry.geom_type.isin(polygon_types)].copy()\n\nprint(gdf_polygons.geometry.geom_type.value_counts())\n",[52,2263,2264,2288,2292,2327,2331],{"__ignoreMap":84},[88,2265,2266,2268,2270,2272,2274,2276,2278,2280,2282,2284,2286],{"class":90,"line":91},[88,2267,1444],{"class":98},[88,2269,136],{"class":135},[88,2271,1449],{"class":142},[88,2273,154],{"class":153},[88,2275,1454],{"class":157},[88,2277,154],{"class":153},[88,2279,212],{"class":142},[88,2281,215],{"class":153},[88,2283,1463],{"class":157},[88,2285,154],{"class":153},[88,2287,315],{"class":142},[88,2289,2290],{"class":90,"line":108},[88,2291,126],{"emptyLinePlaceholder":125},[88,2293,2294,2297,2299,2301,2303,2305,2307,2309,2311,2313,2315,2317,2319,2321,2323,2325],{"class":90,"line":122},[88,2295,2296],{"class":98},"gdf_polygons ",[88,2298,136],{"class":135},[88,2300,2168],{"class":98},[88,2302,206],{"class":142},[88,2304,2128],{"class":98},[88,2306,143],{"class":142},[88,2308,188],{"class":187},[88,2310,143],{"class":142},[88,2312,1091],{"class":187},[88,2314,143],{"class":142},[88,2316,1493],{"class":146},[88,2318,150],{"class":142},[88,2320,1498],{"class":146},[88,2322,1501],{"class":142},[88,2324,756],{"class":146},[88,2326,759],{"class":142},[88,2328,2329],{"class":90,"line":129},[88,2330,126],{"emptyLinePlaceholder":125},[88,2332,2333,2335,2337,2340,2342,2344,2346,2348,2350,2352],{"class":90,"line":166},[88,2334,454],{"class":453},[88,2336,150],{"class":142},[88,2338,2339],{"class":146},"gdf_polygons",[88,2341,143],{"class":142},[88,2343,188],{"class":187},[88,2345,143],{"class":142},[88,2347,1091],{"class":187},[88,2349,143],{"class":142},[88,2351,1096],{"class":146},[88,2353,702],{"class":142},[397,2355,2357],{"id":2356},"example-5-drop-empty-geometries-and-save-cleaned-output","Example 5: Drop empty geometries and save cleaned output",[79,2359,2361],{"className":81,"code":2360,"language":83,"meta":84,"style":84},"cleaned = gdf_fixed.copy()\ncleaned = cleaned[cleaned.geometry.notna()]\ncleaned = cleaned[~cleaned.geometry.is_empty]\ncleaned = cleaned[cleaned.geometry.is_valid]\n\ncleaned.to_file(\"data\u002Fbuildings_cleaned.gpkg\", driver=\"GPKG\")\n",[52,2362,2363,2377,2399,2423,2445,2449],{"__ignoreMap":84},[88,2364,2365,2367,2369,2371,2373,2375],{"class":90,"line":91},[88,2366,1290],{"class":98},[88,2368,136],{"class":135},[88,2370,2168],{"class":98},[88,2372,143],{"class":142},[88,2374,756],{"class":146},[88,2376,759],{"class":142},[88,2378,2379,2381,2383,2385,2387,2389,2391,2393,2395,2397],{"class":90,"line":108},[88,2380,1290],{"class":98},[88,2382,136],{"class":135},[88,2384,1313],{"class":98},[88,2386,206],{"class":142},[88,2388,1318],{"class":98},[88,2390,143],{"class":142},[88,2392,188],{"class":187},[88,2394,143],{"class":142},[88,2396,284],{"class":146},[88,2398,287],{"class":142},[88,2400,2401,2403,2405,2407,2409,2411,2413,2415,2417,2419,2421],{"class":90,"line":122},[88,2402,1290],{"class":98},[88,2404,136],{"class":135},[88,2406,1313],{"class":98},[88,2408,206],{"class":142},[88,2410,301],{"class":135},[88,2412,1318],{"class":98},[88,2414,143],{"class":142},[88,2416,188],{"class":187},[88,2418,143],{"class":142},[88,2420,312],{"class":187},[88,2422,315],{"class":142},[88,2424,2425,2427,2429,2431,2433,2435,2437,2439,2441,2443],{"class":90,"line":129},[88,2426,1290],{"class":98},[88,2428,136],{"class":135},[88,2430,1313],{"class":98},[88,2432,206],{"class":142},[88,2434,1318],{"class":98},[88,2436,143],{"class":142},[88,2438,188],{"class":187},[88,2440,143],{"class":142},[88,2442,337],{"class":187},[88,2444,315],{"class":142},[88,2446,2447],{"class":90,"line":166},[88,2448,126],{"emptyLinePlaceholder":125},[88,2450,2451,2453,2455,2457,2459,2461,2464,2466,2468,2470,2472,2474,2476,2478],{"class":90,"line":171},[88,2452,1318],{"class":98},[88,2454,143],{"class":142},[88,2456,354],{"class":146},[88,2458,150],{"class":142},[88,2460,154],{"class":153},[88,2462,2463],{"class":157},"data\u002Fbuildings_cleaned.gpkg",[88,2465,154],{"class":153},[88,2467,212],{"class":142},[88,2469,369],{"class":368},[88,2471,136],{"class":135},[88,2473,154],{"class":153},[88,2475,376],{"class":157},[88,2477,154],{"class":153},[88,2479,163],{"class":142},[11,2481,2483],{"id":2482},"explanation","Explanation",[16,2485,2486],{},"In practical GIS work, an invalid geometry is a feature that does not meet the structural rules required by geometry libraries. For polygons, common problems include self-intersections, ring issues, or broken parts.",[16,2488,2489],{},"These problems matter because invalid features often break spatial processing before export, especially during:",[23,2491,2492,2494,2496,2498],{},[26,2493,28],{},[26,2495,37],{},[26,2497,34],{},[26,2499,31],{},[16,2501,2502],{},"The repair workflow has three separate steps:",[2504,2505,2506,2511,2516],"ol",{},[26,2507,2508,2509],{},"Check validity with ",[52,2510,546],{},[26,2512,2513,2514],{},"Diagnose the reason with ",[52,2515,715],{},[26,2517,2518,2519,2521,2522],{},"Repair with ",[52,2520,386],{}," or, if necessary, ",[52,2523,390],{},[16,2525,2526],{},"GeoPandas relies on Shapely for these geometry operations, so the repair behavior comes from Shapely.",[16,2528,2529],{},"A key point is that repair can change the geometry structure. One invalid polygon may become:",[23,2531,2532,2537,2541],{},[26,2533,2534,2535],{},"a ",[52,2536,1463],{},[26,2538,2534,2539],{},[52,2540,1541],{},[26,2542,2543],{},"a different valid shape than the original",[16,2545,2546,2547,2549],{},"That is why checking validity is not enough. You should also inspect ",[52,2548,1091],{}," after repair and filter the output if your workflow expects only polygons, only lines, or a single geometry type for export.",[11,2551,2553],{"id":2552},"edge-cases-or-notes","Edge cases or notes",[397,2555,2557,2559],{"id":2556},"make_valid-may-return-different-geometry-types",[52,2558,386],{}," may return different geometry types",[16,2561,2562,2563,2565],{},"A repaired polygon layer may no longer contain only polygons. If your downstream workflow expects polygon-only features, inspect ",[52,2564,1091],{}," and filter before saving.",[397,2567,2569],{"id":2568},"shapefiles-are-restrictive-after-repair","Shapefiles are restrictive after repair",[16,2571,2572,2573,2575],{},"Shapefiles are restrictive. Multipart geometries may be fine if they match the layer type, but mixed geometry types after repair can cause problems. Save to GeoPackage first and inspect ",[52,2574,1091],{}," before exporting to stricter formats.",[397,2577,2579],{"id":2578},"some-invalid-geometries-will-not-repair-cleanly","Some invalid geometries will not repair cleanly",[16,2581,2582],{},"A few features may remain invalid or become empty after repair. In those cases, inspect them manually or remove them from the dataset.",[397,2584,2586,2588],{"id":2585},"buffer0-is-not-a-universal-fix",[52,2587,390],{}," is not a universal fix",[16,2590,2591,2592,2594],{},"It can work for simple polygon self-intersections, but it can also alter geometry shape. Do not use it as the default method if ",[52,2593,386],{}," is available.",[397,2596,2598],{"id":2597},"crs-still-matters","CRS still matters",[16,2600,2601],{},"CRS does not determine whether a geometry is valid, but it still matters for the rest of your workflow. Before overlay or spatial join operations, make sure all layers use the same CRS.",[397,2603,2605],{"id":2604},"valid-does-not-always-mean-correct","Valid does not always mean correct",[16,2607,2608],{},"A geometry can be technically valid and still be wrong for the dataset. Geometry repair fixes structural issues, not mapping mistakes or attribute problems.",[11,2610,2612],{"id":2611},"internal-links","Internal links",[16,2614,2615,2616],{},"For background, see ",[2617,2618,2620],"a",{"href":2619},"\u002Ftasks\u002Ffix-invalid-geometries-python\u002F","Geometry validity in GIS: what makes a feature invalid?",[16,2622,2623],{},"Related task pages:",[23,2625,2626,2632],{},[26,2627,2628],{},[2617,2629,2631],{"href":2630},"\u002Ftasks\u002Fread-shapefile-geopandas\u002F","How to Read a Shapefile in Python with GeoPandas",[26,2633,2634],{},[2617,2635,2637],{"href":2636},"\u002Ftasks\u002Fwrite-geojson-python\u002F","How to Export GeoJSON in Python with GeoPandas",[16,2639,2640,2641],{},"If your processing fails before repair, see ",[2617,2642,2643],{"href":2619},"Why GeoPandas Overlay Fails with TopologyException",[11,2645,2647],{"id":2646},"faq","FAQ",[397,2649,2651],{"id":2650},"what-is-the-best-way-to-fix-invalid-geometries-in-geopandas","What is the best way to fix invalid geometries in GeoPandas?",[16,2653,383,2654,2656,2657,2659],{},[52,2655,386],{}," from Shapely when available. It is the preferred method for most cases. Use ",[52,2658,390],{}," only as a fallback for simple polygon issues.",[397,2661,2663,2664,2666],{"id":2662},"why-does-make_valid-change-my-polygon-into-multiple-parts","Why does ",[52,2665,386],{}," change my polygon into multiple parts?",[16,2668,2669,2670,2672,2673,143],{},"Because the original shape may be structurally broken. Repairing it can split overlapping or self-intersecting areas into valid separate geometries such as ",[52,2671,1463],{}," or ",[52,2674,1541],{},[397,2676,2678,2679,2681],{"id":2677},"can-i-use-buffer0-to-repair-all-invalid-geometries","Can I use ",[52,2680,390],{}," to repair all invalid geometries?",[16,2683,2684],{},"No. It sometimes works for simple self-intersections, but it can change geometry shape and does not fix every invalid case reliably.",[397,2686,2688],{"id":2687},"what-should-i-do-if-repaired-geometries-become-empty-or-still-invalid","What should I do if repaired geometries become empty or still invalid?",[16,2690,2691],{},"Filter out null, empty, or still-invalid rows and inspect those features manually if they matter to the project. Save the cleaned output in a flexible format such as GeoPackage.",[2693,2694,2695],"style",{},"html pre.shiki code .sVHd0, html code.shiki .sVHd0{--shiki-light:#39ADB5;--shiki-light-font-style:italic;--shiki-default:#D73A49;--shiki-default-font-style:inherit;--shiki-dark:#F97583;--shiki-dark-font-style:inherit}html pre.shiki code .su5hD, html code.shiki .su5hD{--shiki-light:#90A4AE;--shiki-default:#24292E;--shiki-dark:#E1E4E8}html pre.shiki code .smGrS, html code.shiki .smGrS{--shiki-light:#39ADB5;--shiki-default:#D73A49;--shiki-dark:#F97583}html pre.shiki code .sP7_E, html code.shiki .sP7_E{--shiki-light:#39ADB5;--shiki-default:#24292E;--shiki-dark:#E1E4E8}html pre.shiki code .slqww, html code.shiki .slqww{--shiki-light:#6182B8;--shiki-default:#24292E;--shiki-dark:#E1E4E8}html pre.shiki code .sjJ54, html code.shiki .sjJ54{--shiki-light:#39ADB5;--shiki-default:#032F62;--shiki-dark:#9ECBFF}html pre.shiki code .s_sjI, html code.shiki .s_sjI{--shiki-light:#91B859;--shiki-default:#032F62;--shiki-dark:#9ECBFF}html pre.shiki code .skxfh, html code.shiki .skxfh{--shiki-light:#E53935;--shiki-default:#24292E;--shiki-dark:#E1E4E8}html pre.shiki code .s99_P, html code.shiki .s99_P{--shiki-light:#90A4AE;--shiki-light-font-style:italic;--shiki-default:#E36209;--shiki-default-font-style:inherit;--shiki-dark:#FFAB70;--shiki-dark-font-style:inherit}html .light .shiki span {color: var(--shiki-light);background: var(--shiki-light-bg);font-style: var(--shiki-light-font-style);font-weight: var(--shiki-light-font-weight);text-decoration: var(--shiki-light-text-decoration);}html.light .shiki span {color: var(--shiki-light);background: var(--shiki-light-bg);font-style: var(--shiki-light-font-style);font-weight: var(--shiki-light-font-weight);text-decoration: var(--shiki-light-text-decoration);}html .default .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html.dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html pre.shiki code .sptTA, html code.shiki .sptTA{--shiki-light:#6182B8;--shiki-default:#005CC5;--shiki-dark:#79B8FF}html pre.shiki code .srdBf, html code.shiki .srdBf{--shiki-light:#F76D47;--shiki-default:#005CC5;--shiki-dark:#79B8FF}",{"title":84,"searchDepth":108,"depth":108,"links":2697},[2698,2699,2700,2712,2720,2721,2731,2732],{"id":13,"depth":108,"text":14},{"id":73,"depth":108,"text":74},{"id":394,"depth":108,"text":395,"children":2701},[2702,2703,2704,2705,2707,2709,2710,2711],{"id":399,"depth":122,"text":400},{"id":540,"depth":122,"text":541},{"id":708,"depth":122,"text":709},{"id":851,"depth":122,"text":2706},"Repair geometries with make_valid()",{"id":1104,"depth":122,"text":2708},"Use buffer(0) as a fallback for simple polygon issues",{"id":1276,"depth":122,"text":1277},{"id":1545,"depth":122,"text":1546},{"id":1666,"depth":122,"text":1667},{"id":1781,"depth":108,"text":1782,"children":2713},[2714,2715,2716,2718,2719],{"id":1785,"depth":122,"text":1786},{"id":1933,"depth":122,"text":1934},{"id":2079,"depth":122,"text":2717},"Example 3: Repair geometries with make_valid()",{"id":2257,"depth":122,"text":2258},{"id":2356,"depth":122,"text":2357},{"id":2482,"depth":108,"text":2483},{"id":2552,"depth":108,"text":2553,"children":2722},[2723,2725,2726,2727,2729,2730],{"id":2556,"depth":122,"text":2724},"make_valid() may return different geometry types",{"id":2568,"depth":122,"text":2569},{"id":2578,"depth":122,"text":2579},{"id":2585,"depth":122,"text":2728},"buffer(0) is not a universal fix",{"id":2597,"depth":122,"text":2598},{"id":2604,"depth":122,"text":2605},{"id":2611,"depth":108,"text":2612},{"id":2646,"depth":108,"text":2647,"children":2733},[2734,2735,2737,2739],{"id":2650,"depth":122,"text":2651},{"id":2662,"depth":122,"text":2736},"Why does make_valid() change my polygon into multiple parts?",{"id":2677,"depth":122,"text":2738},"Can I use buffer(0) to repair all invalid geometries?",{"id":2687,"depth":122,"text":2688},"How to find and fix invalid geometries in GeoPandas using buffer(0), make_valid, and geometry validation checks.","md",{},"\u002Ftasks\u002Ffix-invalid-geometries-python",{"title":6,"description":2740},"tasks\u002Ffix-invalid-geometries-python","_HOAY9t2fuvkSWeMMVkTrsRNHFMQNhKkNt36TB_-hAA",{"id":2748,"title":2631,"body":2749,"description":4331,"extension":2741,"meta":4332,"navigation":125,"path":4333,"seo":4334,"stem":4335,"__hash__":4336},"content\u002Ftasks\u002Fread-shapefile-geopandas.md",{"type":8,"value":2750,"toc":4295},[2751,2753,2756,2759,2773,2776,2782,2784,2794,2850,2855,2873,2875,2879,2882,2901,2904,2908,2911,2914,2931,2934,2941,2944,2952,2958,2962,2965,3035,3044,3048,3051,3056,3075,3079,3104,3108,3132,3136,3155,3159,3178,3181,3185,3188,3192,3264,3271,3351,3356,3359,3361,3365,3419,3423,3694,3700,3803,3807,3964,3966,3975,3985,3996,3999,4009,4024,4027,4040,4043,4046,4050,4057,4060,4078,4081,4085,4098,4101,4130,4133,4137,4140,4143,4166,4169,4173,4176,4180,4183,4187,4190,4192,4199,4210,4215,4225,4227,4234,4246,4250,4253,4267,4272,4276,4285,4289,4292],[11,2752,14],{"id":13},[16,2754,2755],{},"A common GIS task is opening an existing shapefile in Python so you can inspect it, filter it, reproject it, or use it in an automated workflow.",[16,2757,2758],{},"In practice, this usually means:",[23,2760,2761,2764,2767,2770],{},[26,2762,2763],{},"loading a shapefile from a local folder",[26,2765,2766],{},"checking that the attribute table was read correctly",[26,2768,2769],{},"confirming the geometry column exists",[26,2771,2772],{},"verifying the coordinate reference system (CRS)",[16,2774,2775],{},"Typical sources include shapefiles exported from QGIS, downloaded from government open data portals, or shared in project folders on a team drive.",[16,2777,2778,2779,143],{},"If you want to load a shapefile into Python and work with it directly, the standard result is a GeoPandas ",[52,2780,2781],{},"GeoDataFrame",[11,2783,74],{"id":73},[16,2785,383,2786,2789,2790,2793],{},[52,2787,2788],{},"geopandas.read_file()"," and pass it the path to the ",[52,2791,2792],{},".shp"," file:",[79,2795,2797],{"className":81,"code":2796,"language":83,"meta":84,"style":84},"import geopandas as gpd\n\ngdf = gpd.read_file(\"data\u002Froads.shp\")\nprint(gdf.head())\n",[52,2798,2799,2809,2813,2836],{"__ignoreMap":84},[88,2800,2801,2803,2805,2807],{"class":90,"line":91},[88,2802,95],{"class":94},[88,2804,99],{"class":98},[88,2806,102],{"class":94},[88,2808,105],{"class":98},[88,2810,2811],{"class":90,"line":108},[88,2812,126],{"emptyLinePlaceholder":125},[88,2814,2815,2817,2819,2821,2823,2825,2827,2829,2832,2834],{"class":90,"line":122},[88,2816,132],{"class":98},[88,2818,136],{"class":135},[88,2820,139],{"class":98},[88,2822,143],{"class":142},[88,2824,147],{"class":146},[88,2826,150],{"class":142},[88,2828,154],{"class":153},[88,2830,2831],{"class":157},"data\u002Froads.shp",[88,2833,154],{"class":153},[88,2835,163],{"class":142},[88,2837,2838,2840,2842,2844,2846,2848],{"class":90,"line":129},[88,2839,454],{"class":453},[88,2841,150],{"class":142},[88,2843,182],{"class":146},[88,2845,143],{"class":142},[88,2847,699],{"class":146},[88,2849,702],{"class":142},[16,2851,2852,2853,143],{},"This returns a ",[52,2854,2781],{},[16,2856,2857,2858,2860,2861,2864,2865,2868,2869,2872],{},"Important: a shapefile is not just one file. The ",[52,2859,2792],{}," file must be accompanied by other required files, especially ",[52,2862,2863],{},".shx"," and ",[52,2866,2867],{},".dbf",". A ",[52,2870,2871],{},".prj"," file is strongly recommended so GeoPandas can detect the CRS.",[11,2874,395],{"id":394},[397,2876,2878],{"id":2877},"install-geopandas-if-needed","Install GeoPandas if needed",[16,2880,2881],{},"If GeoPandas is not installed yet, install it in a clean environment. GIS Python libraries can have dependency issues, so isolated environments are usually the safest option.",[79,2883,2887],{"className":2884,"code":2885,"language":2886,"meta":84,"style":84},"language-bash shiki shiki-themes material-theme-lighter github-light github-dark","pip install geopandas\n","bash",[52,2888,2889],{"__ignoreMap":84},[88,2890,2891,2895,2898],{"class":90,"line":91},[88,2892,2894],{"class":2893},"sbgvK","pip",[88,2896,2897],{"class":157}," install",[88,2899,2900],{"class":157}," geopandas\n",[16,2902,2903],{},"If installation fails, check your Python environment before troubleshooting the shapefile itself.",[397,2905,2907],{"id":2906},"confirm-the-shapefile-components-are-present","Confirm the shapefile components are present",[16,2909,2910],{},"Before you try to open a shapefile with GeoPandas, check that the required shapefile components are present in the same folder.",[16,2912,2913],{},"At minimum, look for:",[23,2915,2916,2921,2926],{},[26,2917,2918,2920],{},[52,2919,2792],{}," — geometry",[26,2922,2923,2925],{},[52,2924,2863],{}," — shape index",[26,2927,2928,2930],{},[52,2929,2867],{}," — attribute table",[16,2932,2933],{},"Strongly recommended:",[23,2935,2936],{},[26,2937,2938,2940],{},[52,2939,2871],{}," — coordinate reference system definition",[16,2942,2943],{},"Example folder contents:",[79,2945,2950],{"className":2946,"code":2948,"language":2949,"meta":84},[2947],"language-text","parcels.shp\nparcels.shx\nparcels.dbf\nparcels.prj\n","text",[52,2951,2948],{"__ignoreMap":84},[16,2953,2954,2955,2957],{},"If only the ",[52,2956,2792],{}," file is present, the shapefile may fail to load or may load without attributes or other required metadata.",[397,2959,2961],{"id":2960},"read-the-shapefile-with-geopandas","Read the shapefile with GeoPandas",[16,2963,2964],{},"This is the standard workflow:",[79,2966,2968],{"className":81,"code":2967,"language":83,"meta":84,"style":84},"import geopandas as gpd\n\nshapefile_path = \"data\u002Fparcels.shp\"\ngdf = gpd.read_file(shapefile_path)\n\nprint(gdf.head())\n",[52,2969,2970,2980,2984,2998,3017,3021],{"__ignoreMap":84},[88,2971,2972,2974,2976,2978],{"class":90,"line":91},[88,2973,95],{"class":94},[88,2975,99],{"class":98},[88,2977,102],{"class":94},[88,2979,105],{"class":98},[88,2981,2982],{"class":90,"line":108},[88,2983,126],{"emptyLinePlaceholder":125},[88,2985,2986,2989,2991,2993,2995],{"class":90,"line":122},[88,2987,2988],{"class":98},"shapefile_path ",[88,2990,136],{"class":135},[88,2992,215],{"class":153},[88,2994,158],{"class":157},[88,2996,2997],{"class":153},"\"\n",[88,2999,3000,3002,3004,3006,3008,3010,3012,3015],{"class":90,"line":129},[88,3001,132],{"class":98},[88,3003,136],{"class":135},[88,3005,139],{"class":98},[88,3007,143],{"class":142},[88,3009,147],{"class":146},[88,3011,150],{"class":142},[88,3013,3014],{"class":146},"shapefile_path",[88,3016,163],{"class":142},[88,3018,3019],{"class":90,"line":166},[88,3020,126],{"emptyLinePlaceholder":125},[88,3022,3023,3025,3027,3029,3031,3033],{"class":90,"line":171},[88,3024,454],{"class":453},[88,3026,150],{"class":142},[88,3028,182],{"class":146},[88,3030,143],{"class":142},[88,3032,699],{"class":146},[88,3034,702],{"class":142},[16,3036,3037,3038,3040,3041,3043],{},"After loading, ",[52,3039,182],{}," is a ",[52,3042,2781],{},". You can use it for GIS analysis, filtering, plotting, and export.",[397,3045,3047],{"id":3046},"inspect-the-loaded-geodataframe","Inspect the loaded GeoDataFrame",[16,3049,3050],{},"After reading the file, inspect the result immediately.",[3052,3053,3055],"h4",{"id":3054},"preview-rows","Preview rows",[79,3057,3059],{"className":81,"code":3058,"language":83,"meta":84,"style":84},"print(gdf.head())\n",[52,3060,3061],{"__ignoreMap":84},[88,3062,3063,3065,3067,3069,3071,3073],{"class":90,"line":91},[88,3064,454],{"class":453},[88,3066,150],{"class":142},[88,3068,182],{"class":146},[88,3070,143],{"class":142},[88,3072,699],{"class":146},[88,3074,702],{"class":142},[3052,3076,3078],{"id":3077},"check-column-names","Check column names",[79,3080,3082],{"className":81,"code":3081,"language":83,"meta":84,"style":84},"print(gdf.columns.tolist())\n",[52,3083,3084],{"__ignoreMap":84},[88,3085,3086,3088,3090,3092,3094,3097,3099,3102],{"class":90,"line":91},[88,3087,454],{"class":453},[88,3089,150],{"class":142},[88,3091,182],{"class":146},[88,3093,143],{"class":142},[88,3095,3096],{"class":187},"columns",[88,3098,143],{"class":142},[88,3100,3101],{"class":146},"tolist",[88,3103,702],{"class":142},[3052,3105,3107],{"id":3106},"check-geometry-type","Check geometry type",[79,3109,3111],{"className":81,"code":3110,"language":83,"meta":84,"style":84},"print(gdf.geom_type.unique())\n",[52,3112,3113],{"__ignoreMap":84},[88,3114,3115,3117,3119,3121,3123,3125,3127,3130],{"class":90,"line":91},[88,3116,454],{"class":453},[88,3118,150],{"class":142},[88,3120,182],{"class":146},[88,3122,143],{"class":142},[88,3124,1091],{"class":187},[88,3126,143],{"class":142},[88,3128,3129],{"class":146},"unique",[88,3131,702],{"class":142},[3052,3133,3135],{"id":3134},"check-crs","Check CRS",[79,3137,3139],{"className":81,"code":3138,"language":83,"meta":84,"style":84},"print(gdf.crs)\n",[52,3140,3141],{"__ignoreMap":84},[88,3142,3143,3145,3147,3149,3151,3153],{"class":90,"line":91},[88,3144,454],{"class":453},[88,3146,150],{"class":142},[88,3148,182],{"class":146},[88,3150,143],{"class":142},[88,3152,463],{"class":187},[88,3154,163],{"class":142},[3052,3156,3158],{"id":3157},"check-row-count","Check row count",[79,3160,3162],{"className":81,"code":3161,"language":83,"meta":84,"style":84},"print(len(gdf))\n",[52,3163,3164],{"__ignoreMap":84},[88,3165,3166,3168,3170,3172,3174,3176],{"class":90,"line":91},[88,3167,454],{"class":453},[88,3169,150],{"class":142},[88,3171,493],{"class":453},[88,3173,150],{"class":142},[88,3175,182],{"class":146},[88,3177,500],{"class":142},[16,3179,3180],{},"These checks help confirm that the shapefile loaded correctly and is ready for the next GIS step.",[397,3182,3184],{"id":3183},"work-with-file-paths-safely","Work with file paths safely",[16,3186,3187],{},"Path handling is a common source of errors, especially on Windows.",[3052,3189,3191],{"id":3190},"raw-string-example","Raw string example",[79,3193,3195],{"className":81,"code":3194,"language":83,"meta":84,"style":84},"import geopandas as gpd\n\ngdf = gpd.read_file(r\"C:\\gis_projects\\city_data\\buildings.shp\")\n",[52,3196,3197,3207,3211],{"__ignoreMap":84},[88,3198,3199,3201,3203,3205],{"class":90,"line":91},[88,3200,95],{"class":94},[88,3202,99],{"class":98},[88,3204,102],{"class":94},[88,3206,105],{"class":98},[88,3208,3209],{"class":90,"line":108},[88,3210,126],{"emptyLinePlaceholder":125},[88,3212,3213,3215,3217,3219,3221,3223,3225,3229,3231,3235,3239,3242,3245,3248,3252,3255,3257,3260,3262],{"class":90,"line":122},[88,3214,132],{"class":98},[88,3216,136],{"class":135},[88,3218,139],{"class":98},[88,3220,143],{"class":142},[88,3222,147],{"class":146},[88,3224,150],{"class":142},[88,3226,3228],{"class":3227},"sbsja","r",[88,3230,154],{"class":153},[88,3232,3234],{"class":3233},"sQRbd","C:",[88,3236,3238],{"class":3237},"sjYin","\\g",[88,3240,3241],{"class":3233},"is_projects",[88,3243,3244],{"class":3237},"\\c",[88,3246,3247],{"class":3233},"ity_data",[88,3249,3251],{"class":3250},"stzsN","\\b",[88,3253,3254],{"class":3233},"uildings",[88,3256,143],{"class":3250},[88,3258,3259],{"class":3233},"shp",[88,3261,154],{"class":153},[88,3263,163],{"class":142},[3052,3265,3267,3270],{"id":3266},"pathlib-example",[52,3268,3269],{},"pathlib"," example",[79,3272,3274],{"className":81,"code":3273,"language":83,"meta":84,"style":84},"from pathlib import Path\nimport geopandas as gpd\n\nshapefile_path = Path(\"data\") \u002F \"buildings.shp\"\ngdf = gpd.read_file(shapefile_path)\n",[52,3275,3276,3288,3298,3302,3333],{"__ignoreMap":84},[88,3277,3278,3280,3283,3285],{"class":90,"line":91},[88,3279,111],{"class":94},[88,3281,3282],{"class":98}," pathlib ",[88,3284,95],{"class":94},[88,3286,3287],{"class":98}," Path\n",[88,3289,3290,3292,3294,3296],{"class":90,"line":108},[88,3291,95],{"class":94},[88,3293,99],{"class":98},[88,3295,102],{"class":94},[88,3297,105],{"class":98},[88,3299,3300],{"class":90,"line":122},[88,3301,126],{"emptyLinePlaceholder":125},[88,3303,3304,3306,3308,3311,3313,3315,3318,3320,3323,3326,3328,3331],{"class":90,"line":129},[88,3305,2988],{"class":98},[88,3307,136],{"class":135},[88,3309,3310],{"class":146}," Path",[88,3312,150],{"class":142},[88,3314,154],{"class":153},[88,3316,3317],{"class":157},"data",[88,3319,154],{"class":153},[88,3321,3322],{"class":142},")",[88,3324,3325],{"class":135}," \u002F",[88,3327,215],{"class":153},[88,3329,3330],{"class":157},"buildings.shp",[88,3332,2997],{"class":153},[88,3334,3335,3337,3339,3341,3343,3345,3347,3349],{"class":90,"line":166},[88,3336,132],{"class":98},[88,3338,136],{"class":135},[88,3340,139],{"class":98},[88,3342,143],{"class":142},[88,3344,147],{"class":146},[88,3346,150],{"class":142},[88,3348,3014],{"class":146},[88,3350,163],{"class":142},[16,3352,3353,3355],{},[52,3354,3269],{}," is usually the best option because it is cross-platform and easier to maintain in scripts.",[16,3357,3358],{},"Use absolute paths if you are debugging. Use relative paths when building reusable project scripts.",[11,3360,1782],{"id":1781},[397,3362,3364],{"id":3363},"basic-example-read-a-shapefile-from-a-local-path","Basic example: read a shapefile from a local path",[79,3366,3367],{"className":81,"code":2796,"language":83,"meta":84,"style":84},[52,3368,3369,3379,3383,3405],{"__ignoreMap":84},[88,3370,3371,3373,3375,3377],{"class":90,"line":91},[88,3372,95],{"class":94},[88,3374,99],{"class":98},[88,3376,102],{"class":94},[88,3378,105],{"class":98},[88,3380,3381],{"class":90,"line":108},[88,3382,126],{"emptyLinePlaceholder":125},[88,3384,3385,3387,3389,3391,3393,3395,3397,3399,3401,3403],{"class":90,"line":122},[88,3386,132],{"class":98},[88,3388,136],{"class":135},[88,3390,139],{"class":98},[88,3392,143],{"class":142},[88,3394,147],{"class":146},[88,3396,150],{"class":142},[88,3398,154],{"class":153},[88,3400,2831],{"class":157},[88,3402,154],{"class":153},[88,3404,163],{"class":142},[88,3406,3407,3409,3411,3413,3415,3417],{"class":90,"line":129},[88,3408,454],{"class":453},[88,3410,150],{"class":142},[88,3412,182],{"class":146},[88,3414,143],{"class":142},[88,3416,699],{"class":146},[88,3418,702],{"class":142},[397,3420,3422],{"id":3421},"example-inspect-attributes-geometry-and-crs-after-loading","Example: inspect attributes, geometry, and CRS after loading",[79,3424,3426],{"className":81,"code":3425,"language":83,"meta":84,"style":84},"import geopandas as gpd\n\ngdf = gpd.read_file(\"data\u002Fparcels.shp\")\n\nprint(\"First rows:\")\nprint(gdf.head())\n\nprint(\"\\nColumns:\")\nprint(gdf.columns.tolist())\n\nprint(\"\\nGeometry column:\")\nprint(gdf.geometry.name)\n\nprint(\"\\nGeometry types:\")\nprint(gdf.geom_type.unique())\n\nprint(\"\\nCRS:\")\nprint(gdf.crs)\n\nprint(\"\\nRow count:\")\nprint(len(gdf))\n",[52,3427,3428,3438,3442,3464,3468,3483,3497,3501,3520,3538,3542,3559,3577,3581,3599,3618,3623,3641,3656,3661,3679],{"__ignoreMap":84},[88,3429,3430,3432,3434,3436],{"class":90,"line":91},[88,3431,95],{"class":94},[88,3433,99],{"class":98},[88,3435,102],{"class":94},[88,3437,105],{"class":98},[88,3439,3440],{"class":90,"line":108},[88,3441,126],{"emptyLinePlaceholder":125},[88,3443,3444,3446,3448,3450,3452,3454,3456,3458,3460,3462],{"class":90,"line":122},[88,3445,132],{"class":98},[88,3447,136],{"class":135},[88,3449,139],{"class":98},[88,3451,143],{"class":142},[88,3453,147],{"class":146},[88,3455,150],{"class":142},[88,3457,154],{"class":153},[88,3459,158],{"class":157},[88,3461,154],{"class":153},[88,3463,163],{"class":142},[88,3465,3466],{"class":90,"line":129},[88,3467,126],{"emptyLinePlaceholder":125},[88,3469,3470,3472,3474,3476,3479,3481],{"class":90,"line":166},[88,3471,454],{"class":453},[88,3473,150],{"class":142},[88,3475,154],{"class":153},[88,3477,3478],{"class":157},"First rows:",[88,3480,154],{"class":153},[88,3482,163],{"class":142},[88,3484,3485,3487,3489,3491,3493,3495],{"class":90,"line":171},[88,3486,454],{"class":453},[88,3488,150],{"class":142},[88,3490,182],{"class":146},[88,3492,143],{"class":142},[88,3494,699],{"class":146},[88,3496,702],{"class":142},[88,3498,3499],{"class":90,"line":196},[88,3500,126],{"emptyLinePlaceholder":125},[88,3502,3503,3505,3507,3509,3513,3516,3518],{"class":90,"line":260},[88,3504,454],{"class":453},[88,3506,150],{"class":142},[88,3508,154],{"class":153},[88,3510,3512],{"class":3511},"s_hVV","\\n",[88,3514,3515],{"class":157},"Columns:",[88,3517,154],{"class":153},[88,3519,163],{"class":142},[88,3521,3522,3524,3526,3528,3530,3532,3534,3536],{"class":90,"line":265},[88,3523,454],{"class":453},[88,3525,150],{"class":142},[88,3527,182],{"class":146},[88,3529,143],{"class":142},[88,3531,3096],{"class":187},[88,3533,143],{"class":142},[88,3535,3101],{"class":146},[88,3537,702],{"class":142},[88,3539,3540],{"class":90,"line":290},[88,3541,126],{"emptyLinePlaceholder":125},[88,3543,3544,3546,3548,3550,3552,3555,3557],{"class":90,"line":318},[88,3545,454],{"class":453},[88,3547,150],{"class":142},[88,3549,154],{"class":153},[88,3551,3512],{"class":3511},[88,3553,3554],{"class":157},"Geometry column:",[88,3556,154],{"class":153},[88,3558,163],{"class":142},[88,3560,3561,3563,3565,3567,3569,3571,3573,3575],{"class":90,"line":342},[88,3562,454],{"class":453},[88,3564,150],{"class":142},[88,3566,182],{"class":146},[88,3568,143],{"class":142},[88,3570,188],{"class":187},[88,3572,143],{"class":142},[88,3574,482],{"class":187},[88,3576,163],{"class":142},[88,3578,3579],{"class":90,"line":347},[88,3580,126],{"emptyLinePlaceholder":125},[88,3582,3584,3586,3588,3590,3592,3595,3597],{"class":90,"line":3583},14,[88,3585,454],{"class":453},[88,3587,150],{"class":142},[88,3589,154],{"class":153},[88,3591,3512],{"class":3511},[88,3593,3594],{"class":157},"Geometry types:",[88,3596,154],{"class":153},[88,3598,163],{"class":142},[88,3600,3602,3604,3606,3608,3610,3612,3614,3616],{"class":90,"line":3601},15,[88,3603,454],{"class":453},[88,3605,150],{"class":142},[88,3607,182],{"class":146},[88,3609,143],{"class":142},[88,3611,1091],{"class":187},[88,3613,143],{"class":142},[88,3615,3129],{"class":146},[88,3617,702],{"class":142},[88,3619,3621],{"class":90,"line":3620},16,[88,3622,126],{"emptyLinePlaceholder":125},[88,3624,3626,3628,3630,3632,3634,3637,3639],{"class":90,"line":3625},17,[88,3627,454],{"class":453},[88,3629,150],{"class":142},[88,3631,154],{"class":153},[88,3633,3512],{"class":3511},[88,3635,3636],{"class":157},"CRS:",[88,3638,154],{"class":153},[88,3640,163],{"class":142},[88,3642,3644,3646,3648,3650,3652,3654],{"class":90,"line":3643},18,[88,3645,454],{"class":453},[88,3647,150],{"class":142},[88,3649,182],{"class":146},[88,3651,143],{"class":142},[88,3653,463],{"class":187},[88,3655,163],{"class":142},[88,3657,3659],{"class":90,"line":3658},19,[88,3660,126],{"emptyLinePlaceholder":125},[88,3662,3664,3666,3668,3670,3672,3675,3677],{"class":90,"line":3663},20,[88,3665,454],{"class":453},[88,3667,150],{"class":142},[88,3669,154],{"class":153},[88,3671,3512],{"class":3511},[88,3673,3674],{"class":157},"Row count:",[88,3676,154],{"class":153},[88,3678,163],{"class":142},[88,3680,3682,3684,3686,3688,3690,3692],{"class":90,"line":3681},21,[88,3683,454],{"class":453},[88,3685,150],{"class":142},[88,3687,493],{"class":453},[88,3689,150],{"class":142},[88,3691,182],{"class":146},[88,3693,500],{"class":142},[397,3695,3697,3698],{"id":3696},"example-read-a-shapefile-using-pathlib","Example: read a shapefile using ",[52,3699,3269],{},[79,3701,3703],{"className":81,"code":3702,"language":83,"meta":84,"style":84},"from pathlib import Path\nimport geopandas as gpd\n\nbase_dir = Path(\"data\")\nshapefile_path = base_dir \u002F \"admin_boundaries.shp\"\n\ngdf = gpd.read_file(shapefile_path)\nprint(gdf.head())\n",[52,3704,3705,3715,3725,3729,3748,3767,3771,3789],{"__ignoreMap":84},[88,3706,3707,3709,3711,3713],{"class":90,"line":91},[88,3708,111],{"class":94},[88,3710,3282],{"class":98},[88,3712,95],{"class":94},[88,3714,3287],{"class":98},[88,3716,3717,3719,3721,3723],{"class":90,"line":108},[88,3718,95],{"class":94},[88,3720,99],{"class":98},[88,3722,102],{"class":94},[88,3724,105],{"class":98},[88,3726,3727],{"class":90,"line":122},[88,3728,126],{"emptyLinePlaceholder":125},[88,3730,3731,3734,3736,3738,3740,3742,3744,3746],{"class":90,"line":129},[88,3732,3733],{"class":98},"base_dir ",[88,3735,136],{"class":135},[88,3737,3310],{"class":146},[88,3739,150],{"class":142},[88,3741,154],{"class":153},[88,3743,3317],{"class":157},[88,3745,154],{"class":153},[88,3747,163],{"class":142},[88,3749,3750,3752,3754,3757,3760,3762,3765],{"class":90,"line":166},[88,3751,2988],{"class":98},[88,3753,136],{"class":135},[88,3755,3756],{"class":98}," base_dir ",[88,3758,3759],{"class":135},"\u002F",[88,3761,215],{"class":153},[88,3763,3764],{"class":157},"admin_boundaries.shp",[88,3766,2997],{"class":153},[88,3768,3769],{"class":90,"line":171},[88,3770,126],{"emptyLinePlaceholder":125},[88,3772,3773,3775,3777,3779,3781,3783,3785,3787],{"class":90,"line":196},[88,3774,132],{"class":98},[88,3776,136],{"class":135},[88,3778,139],{"class":98},[88,3780,143],{"class":142},[88,3782,147],{"class":146},[88,3784,150],{"class":142},[88,3786,3014],{"class":146},[88,3788,163],{"class":142},[88,3790,3791,3793,3795,3797,3799,3801],{"class":90,"line":260},[88,3792,454],{"class":453},[88,3794,150],{"class":142},[88,3796,182],{"class":146},[88,3798,143],{"class":142},[88,3800,699],{"class":146},[88,3802,702],{"class":142},[397,3804,3806],{"id":3805},"example-check-that-the-file-exists-before-reading","Example: check that the file exists before reading",[79,3808,3810],{"className":81,"code":3809,"language":83,"meta":84,"style":84},"from pathlib import Path\nimport geopandas as gpd\n\nshapefile_path = Path(\"data\") \u002F \"land_use.shp\"\n\nif not shapefile_path.exists():\n    raise FileNotFoundError(f\"Shapefile not found: {shapefile_path}\")\n\ngdf = gpd.read_file(shapefile_path)\nprint(f\"Loaded {len(gdf)} features\")\n",[52,3811,3812,3822,3832,3836,3863,3867,3885,3914,3918,3936],{"__ignoreMap":84},[88,3813,3814,3816,3818,3820],{"class":90,"line":91},[88,3815,111],{"class":94},[88,3817,3282],{"class":98},[88,3819,95],{"class":94},[88,3821,3287],{"class":98},[88,3823,3824,3826,3828,3830],{"class":90,"line":108},[88,3825,95],{"class":94},[88,3827,99],{"class":98},[88,3829,102],{"class":94},[88,3831,105],{"class":98},[88,3833,3834],{"class":90,"line":122},[88,3835,126],{"emptyLinePlaceholder":125},[88,3837,3838,3840,3842,3844,3846,3848,3850,3852,3854,3856,3858,3861],{"class":90,"line":129},[88,3839,2988],{"class":98},[88,3841,136],{"class":135},[88,3843,3310],{"class":146},[88,3845,150],{"class":142},[88,3847,154],{"class":153},[88,3849,3317],{"class":157},[88,3851,154],{"class":153},[88,3853,3322],{"class":142},[88,3855,3325],{"class":135},[88,3857,215],{"class":153},[88,3859,3860],{"class":157},"land_use.shp",[88,3862,2997],{"class":153},[88,3864,3865],{"class":90,"line":166},[88,3866,126],{"emptyLinePlaceholder":125},[88,3868,3869,3872,3875,3878,3880,3883],{"class":90,"line":171},[88,3870,3871],{"class":94},"if",[88,3873,3874],{"class":135}," not",[88,3876,3877],{"class":98}," shapefile_path",[88,3879,143],{"class":142},[88,3881,3882],{"class":146},"exists",[88,3884,2050],{"class":142},[88,3886,3887,3890,3894,3896,3899,3902,3905,3907,3910,3912],{"class":90,"line":196},[88,3888,3889],{"class":94},"    raise",[88,3891,3893],{"class":3892},"sZMiF"," FileNotFoundError",[88,3895,150],{"class":142},[88,3897,3898],{"class":3227},"f",[88,3900,3901],{"class":157},"\"Shapefile not found: ",[88,3903,3904],{"class":822},"{",[88,3906,3014],{"class":146},[88,3908,3909],{"class":822},"}",[88,3911,154],{"class":157},[88,3913,163],{"class":142},[88,3915,3916],{"class":90,"line":260},[88,3917,126],{"emptyLinePlaceholder":125},[88,3919,3920,3922,3924,3926,3928,3930,3932,3934],{"class":90,"line":265},[88,3921,132],{"class":98},[88,3923,136],{"class":135},[88,3925,139],{"class":98},[88,3927,143],{"class":142},[88,3929,147],{"class":146},[88,3931,150],{"class":142},[88,3933,3014],{"class":146},[88,3935,163],{"class":142},[88,3937,3938,3940,3942,3944,3947,3949,3951,3953,3955,3957,3959,3962],{"class":90,"line":290},[88,3939,454],{"class":453},[88,3941,150],{"class":142},[88,3943,3898],{"class":3227},[88,3945,3946],{"class":157},"\"Loaded ",[88,3948,3904],{"class":822},[88,3950,493],{"class":453},[88,3952,150],{"class":142},[88,3954,182],{"class":146},[88,3956,3322],{"class":142},[88,3958,3909],{"class":822},[88,3960,3961],{"class":157}," features\"",[88,3963,163],{"class":142},[11,3965,2483],{"id":2482},[16,3967,3968,3969,3972,3973,143],{},"When you use ",[52,3970,3971],{},"gpd.read_file()",", GeoPandas reads the vector dataset and returns a ",[52,3974,2781],{},[16,3976,3977,3978,3980,3981,3984],{},"A ",[52,3979,2781],{}," is similar to a pandas ",[52,3982,3983],{},"DataFrame",", but it includes:",[23,3986,3987,3990,3993],{},[26,3988,3989],{},"a geometry column",[26,3991,3992],{},"spatial methods",[26,3994,3995],{},"CRS metadata",[16,3997,3998],{},"That makes it the standard structure for vector data work in GeoPandas.",[16,4000,4001,4002,4005,4006,4008],{},"Under the hood, ",[52,4003,4004],{},"read_file()"," uses the installed vector I\u002FO engine, commonly Fiona or Pyogrio depending on your environment. In normal use, you do not need to manage this directly. The important part is that ",[52,4007,4004],{}," is the standard function for loading shapefiles.",[16,4010,4011,4012,4014,4015,4017,4018,4020,4021,4023],{},"It also helps to remember that a shapefile is a multi-file format, not a single standalone ",[52,4013,2792],{}," file. The ",[52,4016,2792],{}," stores geometry, the ",[52,4019,2867],{}," stores attributes, and the ",[52,4022,2863],{}," stores index information. If one of these files is missing, loading may fail or important data may be missing.",[16,4025,4026],{},"Check the CRS as soon as you load the data. Many GIS operations depend on it, including:",[23,4028,4029,4032,4034,4037],{},[26,4030,4031],{},"reprojection",[26,4033,31],{},[26,4035,4036],{},"distance calculations",[26,4038,4039],{},"area calculations",[16,4041,4042],{},"If the CRS is missing or wrong, downstream results can be incorrect.",[16,4044,4045],{},"Shapefiles also have format limitations. For example, attribute field names are often truncated because the format has older field name length restrictions. For new projects, formats like GeoPackage are often a better choice, but shapefiles are still very common in GIS workflows.",[11,4047,4049],{"id":4048},"edge-cases-and-notes","Edge cases and notes",[397,4051,4053,4054,4056],{"id":4052},"the-shp-file-exists-but-the-shapefile-still-fails-to-load","The ",[52,4055,2792],{}," file exists but the shapefile still fails to load",[16,4058,4059],{},"Common causes:",[23,4061,4062,4069,4072,4075],{},[26,4063,4064,4065,2672,4067],{},"missing ",[52,4066,2863],{},[52,4068,2867],{},[26,4070,4071],{},"corrupted shapefile components",[26,4073,4074],{},"wrong path",[26,4076,4077],{},"trying to read from a zipped archive instead of an extracted folder",[16,4079,4080],{},"Start by checking the folder contents and testing the same dataset in QGIS.",[397,4082,4084],{"id":4083},"crs-is-missing-after-reading","CRS is missing after reading",[16,4086,1110,4087,4090,4091,4094,4095,4097],{},[52,4088,4089],{},"gdf.crs"," is ",[52,4092,4093],{},"None",", the shapefile probably does not include a ",[52,4096,2871],{}," file.",[16,4099,4100],{},"You may need to assign the CRS manually before doing spatial operations:",[79,4102,4104],{"className":81,"code":4103,"language":83,"meta":84,"style":84},"gdf = gdf.set_crs(\"EPSG:4326\")\n",[52,4105,4106],{"__ignoreMap":84},[88,4107,4108,4110,4112,4114,4116,4119,4121,4123,4126,4128],{"class":90,"line":91},[88,4109,132],{"class":98},[88,4111,136],{"class":135},[88,4113,228],{"class":98},[88,4115,143],{"class":142},[88,4117,4118],{"class":146},"set_crs",[88,4120,150],{"class":142},[88,4122,154],{"class":153},[88,4124,4125],{"class":157},"EPSG:4326",[88,4127,154],{"class":153},[88,4129,163],{"class":142},[16,4131,4132],{},"Only do this if you know the source CRS is correct.",[397,4134,4136],{"id":4135},"invalid-geometries","Invalid geometries",[16,4138,4139],{},"The shapefile may load successfully but still contain bad geometry. That becomes a problem later during overlays, dissolves, or spatial joins.",[16,4141,4142],{},"Quick check:",[79,4144,4146],{"className":81,"code":4145,"language":83,"meta":84,"style":84},"print(gdf.is_valid.value_counts())\n",[52,4147,4148],{"__ignoreMap":84},[88,4149,4150,4152,4154,4156,4158,4160,4162,4164],{"class":90,"line":91},[88,4151,454],{"class":453},[88,4153,150],{"class":142},[88,4155,182],{"class":146},[88,4157,143],{"class":142},[88,4159,337],{"class":187},[88,4161,143],{"class":142},[88,4163,1096],{"class":146},[88,4165,702],{"class":142},[16,4167,4168],{},"If many features are invalid, fix geometry issues before analysis.",[397,4170,4172],{"id":4171},"column-names-look-truncated","Column names look truncated",[16,4174,4175],{},"This is a normal shapefile limitation. Long field names are often shortened when the shapefile was created. If preserving full field names matters, use a newer format for exports.",[397,4177,4179],{"id":4178},"encoding-issues-in-attribute-data","Encoding issues in attribute data",[16,4181,4182],{},"Older shapefiles from external sources may have text encoding problems. If attribute values look corrupted, inspect the source data and, if needed, re-export it from QGIS or another GIS tool into a newer format.",[397,4184,4186],{"id":4185},"reading-zipped-or-network-stored-shapefiles","Reading zipped or network-stored shapefiles",[16,4188,4189],{},"For reliability, start with a local extracted shapefile folder rather than a zipped archive or network location while debugging.",[11,4191,2612],{"id":2611},[16,4193,4194,4195,143],{},"If you want to understand the structure returned by GeoPandas, see ",[2617,4196,4198],{"href":4197},"\u002Ffoundation\u002Fgeopandas-basics\u002F","What Is a GeoDataFrame in GeoPandas?",[16,4200,4201,4202,2864,4206,143],{},"For the next step after loading data, see ",[2617,4203,4205],{"href":4204},"\u002Ftasks\u002Freproject-geodataframe-python\u002F","How to Reproject Spatial Data in Python (GeoPandas)",[2617,4207,4209],{"href":4208},"\u002Ftasks\u002Fspatial-join-python-geopandas\u002F","How to Perform a Spatial Join in Python (GeoPandas)",[16,4211,4212,4213,143],{},"If you need to export the data after inspection or cleanup, see ",[2617,4214,2637],{"href":2636},[16,4216,1110,4217,4219,4220,4224],{},[52,4218,4004],{}," fails, use ",[2617,4221,4223],{"href":4222},"\u002Ftroubleshooting\u002Fgeopandas-not-reading-shapefile\u002F","Why GeoPandas read_file Is Not Working"," for dependency, path, and file-format troubleshooting.",[11,4226,2647],{"id":2646},[397,4228,4230,4231,4233],{"id":4229},"can-geopandas-read-a-shp-file-directly","Can GeoPandas read a ",[52,4232,2792],{}," file directly?",[16,4235,4236,4237,4239,4240,4242,4243,4245],{},"Yes. Use ",[52,4238,2788],{}," and pass the path to the ",[52,4241,2792],{}," file. GeoPandas will load it as a ",[52,4244,2781],{}," if the required companion files are present.",[397,4247,4249],{"id":4248},"what-files-are-required-for-a-shapefile-to-work-correctly","What files are required for a shapefile to work correctly?",[16,4251,4252],{},"The key files are:",[23,4254,4255,4259,4263],{},[26,4256,4257],{},[52,4258,2792],{},[26,4260,4261],{},[52,4262,2863],{},[26,4264,4265],{},[52,4266,2867],{},[16,4268,3977,4269,4271],{},[52,4270,2871],{}," file is also important because it stores CRS information. Without it, the data may load with no CRS defined.",[397,4273,4275],{"id":4274},"why-is-the-crs-missing-after-i-load-a-shapefile","Why is the CRS missing after I load a shapefile?",[16,4277,4278,4279,4281,4282,143],{},"Usually because the shapefile has no ",[52,4280,2871],{}," file. In that case, GeoPandas cannot determine the coordinate system automatically. If you know the correct CRS, assign it manually with ",[52,4283,4284],{},"set_crs()",[397,4286,4288],{"id":4287},"why-are-my-shapefile-column-names-shortened","Why are my shapefile column names shortened?",[16,4290,4291],{},"This is a standard shapefile limitation. The format has older field naming constraints, so long attribute names are often truncated when the shapefile is created.",[2693,4293,4294],{},"html pre.shiki code .sVHd0, html code.shiki .sVHd0{--shiki-light:#39ADB5;--shiki-light-font-style:italic;--shiki-default:#D73A49;--shiki-default-font-style:inherit;--shiki-dark:#F97583;--shiki-dark-font-style:inherit}html pre.shiki code .su5hD, html code.shiki .su5hD{--shiki-light:#90A4AE;--shiki-default:#24292E;--shiki-dark:#E1E4E8}html pre.shiki code .smGrS, html code.shiki .smGrS{--shiki-light:#39ADB5;--shiki-default:#D73A49;--shiki-dark:#F97583}html pre.shiki code .sP7_E, html code.shiki .sP7_E{--shiki-light:#39ADB5;--shiki-default:#24292E;--shiki-dark:#E1E4E8}html pre.shiki code .slqww, html code.shiki .slqww{--shiki-light:#6182B8;--shiki-default:#24292E;--shiki-dark:#E1E4E8}html pre.shiki code .sjJ54, html code.shiki .sjJ54{--shiki-light:#39ADB5;--shiki-default:#032F62;--shiki-dark:#9ECBFF}html pre.shiki code .s_sjI, html code.shiki .s_sjI{--shiki-light:#91B859;--shiki-default:#032F62;--shiki-dark:#9ECBFF}html pre.shiki code .sptTA, html code.shiki .sptTA{--shiki-light:#6182B8;--shiki-default:#005CC5;--shiki-dark:#79B8FF}html .light .shiki span {color: var(--shiki-light);background: var(--shiki-light-bg);font-style: var(--shiki-light-font-style);font-weight: var(--shiki-light-font-weight);text-decoration: var(--shiki-light-text-decoration);}html.light .shiki span {color: var(--shiki-light);background: var(--shiki-light-bg);font-style: var(--shiki-light-font-style);font-weight: var(--shiki-light-font-weight);text-decoration: var(--shiki-light-text-decoration);}html .default .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html.dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html pre.shiki code .sbgvK, html code.shiki .sbgvK{--shiki-light:#E2931D;--shiki-default:#6F42C1;--shiki-dark:#B392F0}html pre.shiki code .skxfh, html code.shiki .skxfh{--shiki-light:#E53935;--shiki-default:#24292E;--shiki-dark:#E1E4E8}html pre.shiki code .sbsja, html code.shiki .sbsja{--shiki-light:#9C3EDA;--shiki-default:#D73A49;--shiki-dark:#F97583}html pre.shiki code .sQRbd, html code.shiki .sQRbd{--shiki-light:#91B859;--shiki-default:#032F62;--shiki-dark:#DBEDFF}html pre.shiki code .sjYin, html code.shiki .sjYin{--shiki-light:#90A4AE;--shiki-light-font-weight:inherit;--shiki-default:#22863A;--shiki-default-font-weight:bold;--shiki-dark:#85E89D;--shiki-dark-font-weight:bold}html pre.shiki code .stzsN, html code.shiki .stzsN{--shiki-light:#91B859;--shiki-default:#005CC5;--shiki-dark:#79B8FF}html pre.shiki code .s_hVV, html code.shiki .s_hVV{--shiki-light:#90A4AE;--shiki-default:#005CC5;--shiki-dark:#79B8FF}html pre.shiki code .sZMiF, html code.shiki .sZMiF{--shiki-light:#E2931D;--shiki-default:#005CC5;--shiki-dark:#79B8FF}html pre.shiki code .srdBf, html code.shiki .srdBf{--shiki-light:#F76D47;--shiki-default:#005CC5;--shiki-dark:#79B8FF}",{"title":84,"searchDepth":108,"depth":108,"links":4296},[4297,4298,4299,4306,4313,4314,4323,4324],{"id":13,"depth":108,"text":14},{"id":73,"depth":108,"text":74},{"id":394,"depth":108,"text":395,"children":4300},[4301,4302,4303,4304,4305],{"id":2877,"depth":122,"text":2878},{"id":2906,"depth":122,"text":2907},{"id":2960,"depth":122,"text":2961},{"id":3046,"depth":122,"text":3047},{"id":3183,"depth":122,"text":3184},{"id":1781,"depth":108,"text":1782,"children":4307},[4308,4309,4310,4312],{"id":3363,"depth":122,"text":3364},{"id":3421,"depth":122,"text":3422},{"id":3696,"depth":122,"text":4311},"Example: read a shapefile using pathlib",{"id":3805,"depth":122,"text":3806},{"id":2482,"depth":108,"text":2483},{"id":4048,"depth":108,"text":4049,"children":4315},[4316,4318,4319,4320,4321,4322],{"id":4052,"depth":122,"text":4317},"The .shp file exists but the shapefile still fails to load",{"id":4083,"depth":122,"text":4084},{"id":4135,"depth":122,"text":4136},{"id":4171,"depth":122,"text":4172},{"id":4178,"depth":122,"text":4179},{"id":4185,"depth":122,"text":4186},{"id":2611,"depth":108,"text":2612},{"id":2646,"depth":108,"text":2647,"children":4325},[4326,4328,4329,4330],{"id":4229,"depth":122,"text":4327},"Can GeoPandas read a .shp file directly?",{"id":4248,"depth":122,"text":4249},{"id":4274,"depth":122,"text":4275},{"id":4287,"depth":122,"text":4288},"Step-by-step guide to reading a shapefile in Python using GeoPandas, with examples and common issues covered.",{},"\u002Ftasks\u002Fread-shapefile-geopandas",{"title":2631,"description":4331},"tasks\u002Fread-shapefile-geopandas","e09mD9LMG8AB6GFxdsRvtWS5Gcm-GLzFUjp8o3ehG2A",{"id":4338,"title":4205,"body":4339,"description":6317,"extension":2741,"meta":6318,"navigation":125,"path":6319,"seo":6320,"stem":6321,"__hash__":6322},"content\u002Ftasks\u002Freproject-geodataframe-python.md",{"type":8,"value":4340,"toc":6278},[4341,4343,4346,4349,4369,4372,4374,4381,4384,4406,4409,4509,4515,4517,4521,4524,4579,4582,4598,4601,4604,4623,4626,4630,4713,4716,4720,4726,4736,4785,4792,4798,5012,5018,5024,5030,5036,5045,5188,5196,5201,5204,5217,5221,5226,5353,5356,5360,5363,5367,5453,5456,5523,5526,5569,5571,5575,5718,5722,5725,5871,5873,5881,5884,5888,5891,5897,5924,5928,5931,5936,5963,5975,5979,5984,5987,6004,6007,6024,6027,6031,6034,6037,6053,6056,6060,6064,6096,6099,6134,6137,6139,6146,6149,6159,6164,6171,6173,6177,6185,6212,6221,6232,6236,6239,6265,6269,6275],[11,4342,14],{"id":13},[16,4344,4345],{},"A common GIS task is changing the coordinate reference system of vector data so it matches another layer, works with web maps, or produces correct distance and area results.",[16,4347,4348],{},"Typical cases include:",[23,4350,4351,4360,4363,4366],{},[26,4352,4353,4354,4356,4357],{},"a shapefile in ",[52,4355,4125],{}," needs to display with web tiles in ",[52,4358,4359],{},"EPSG:3857",[26,4361,4362],{},"you need a projected CRS before calculating area, length, or buffers",[26,4364,4365],{},"two datasets do not align because they use different CRS values",[26,4367,4368],{},"a file has valid coordinates, but the CRS metadata is missing",[16,4370,4371],{},"If you need to reproject a GeoDataFrame in Python, the main issue is knowing whether the CRS is already defined correctly. If it is, you transform it. If it is missing but known from external metadata or documentation, you assign it first.",[11,4373,74],{"id":73},[16,4375,4376,4377,4380],{},"Use GeoPandas ",[52,4378,4379],{},".to_crs()"," to reproject geometries.",[16,4382,4383],{},"Basic workflow:",[2504,4385,4386,4391,4397,4403],{},[26,4387,4388,4389],{},"check the current CRS with ",[52,4390,4089],{},[26,4392,4393,4394],{},"if the CRS is missing but known, assign it with ",[52,4395,4396],{},"gdf.set_crs()",[26,4398,4399,4400],{},"reproject with ",[52,4401,4402],{},"gdf.to_crs(...)",[26,4404,4405],{},"save the result or continue analysis",[16,4407,4408],{},"Example:",[79,4410,4412],{"className":81,"code":4411,"language":83,"meta":84,"style":84},"import geopandas as gpd\n\ngdf = gpd.read_file(\"data\u002Froads.shp\")\nprint(gdf.crs)\n\ngdf_3857 = gdf.to_crs(epsg=3857)\nprint(gdf_3857.crs)\n",[52,4413,4414,4424,4428,4450,4464,4468,4494],{"__ignoreMap":84},[88,4415,4416,4418,4420,4422],{"class":90,"line":91},[88,4417,95],{"class":94},[88,4419,99],{"class":98},[88,4421,102],{"class":94},[88,4423,105],{"class":98},[88,4425,4426],{"class":90,"line":108},[88,4427,126],{"emptyLinePlaceholder":125},[88,4429,4430,4432,4434,4436,4438,4440,4442,4444,4446,4448],{"class":90,"line":122},[88,4431,132],{"class":98},[88,4433,136],{"class":135},[88,4435,139],{"class":98},[88,4437,143],{"class":142},[88,4439,147],{"class":146},[88,4441,150],{"class":142},[88,4443,154],{"class":153},[88,4445,2831],{"class":157},[88,4447,154],{"class":153},[88,4449,163],{"class":142},[88,4451,4452,4454,4456,4458,4460,4462],{"class":90,"line":129},[88,4453,454],{"class":453},[88,4455,150],{"class":142},[88,4457,182],{"class":146},[88,4459,143],{"class":142},[88,4461,463],{"class":187},[88,4463,163],{"class":142},[88,4465,4466],{"class":90,"line":166},[88,4467,126],{"emptyLinePlaceholder":125},[88,4469,4470,4473,4475,4477,4479,4482,4484,4487,4489,4492],{"class":90,"line":171},[88,4471,4472],{"class":98},"gdf_3857 ",[88,4474,136],{"class":135},[88,4476,228],{"class":98},[88,4478,143],{"class":142},[88,4480,4481],{"class":146},"to_crs",[88,4483,150],{"class":142},[88,4485,4486],{"class":368},"epsg",[88,4488,136],{"class":135},[88,4490,4491],{"class":822},"3857",[88,4493,163],{"class":142},[88,4495,4496,4498,4500,4503,4505,4507],{"class":90,"line":196},[88,4497,454],{"class":453},[88,4499,150],{"class":142},[88,4501,4502],{"class":146},"gdf_3857",[88,4504,143],{"class":142},[88,4506,463],{"class":187},[88,4508,163],{"class":142},[16,4510,4511,4512,4514],{},"Important: ",[52,4513,4379],{}," only works correctly if the current CRS is already defined correctly.",[11,4516,395],{"id":394},[397,4518,4520],{"id":4519},"check-the-current-crs","Check the current CRS",[16,4522,4523],{},"Before changing anything, inspect the CRS.",[79,4525,4527],{"className":81,"code":4526,"language":83,"meta":84,"style":84},"import geopandas as gpd\n\ngdf = gpd.read_file(\"data\u002Fparcels.shp\")\nprint(gdf.crs)\n",[52,4528,4529,4539,4543,4565],{"__ignoreMap":84},[88,4530,4531,4533,4535,4537],{"class":90,"line":91},[88,4532,95],{"class":94},[88,4534,99],{"class":98},[88,4536,102],{"class":94},[88,4538,105],{"class":98},[88,4540,4541],{"class":90,"line":108},[88,4542,126],{"emptyLinePlaceholder":125},[88,4544,4545,4547,4549,4551,4553,4555,4557,4559,4561,4563],{"class":90,"line":122},[88,4546,132],{"class":98},[88,4548,136],{"class":135},[88,4550,139],{"class":98},[88,4552,143],{"class":142},[88,4554,147],{"class":146},[88,4556,150],{"class":142},[88,4558,154],{"class":153},[88,4560,158],{"class":157},[88,4562,154],{"class":153},[88,4564,163],{"class":142},[88,4566,4567,4569,4571,4573,4575,4577],{"class":90,"line":129},[88,4568,454],{"class":453},[88,4570,150],{"class":142},[88,4572,182],{"class":146},[88,4574,143],{"class":142},[88,4576,463],{"class":187},[88,4578,163],{"class":142},[16,4580,4581],{},"Example output:",[79,4583,4585],{"className":81,"code":4584,"language":83,"meta":84,"style":84},"EPSG:4326\n",[52,4586,4587],{"__ignoreMap":84},[88,4588,4589,4592,4595],{"class":90,"line":91},[88,4590,4591],{"class":3511},"EPSG",[88,4593,4594],{"class":142},":",[88,4596,4597],{"class":822},"4326\n",[16,4599,4600],{},"This tells you what coordinate system the current geometry coordinates use.",[16,4602,4603],{},"You need to distinguish between:",[23,4605,4606,4617],{},[26,4607,4608,4612,4613,4090,4615],{},[4609,4610,4611],"strong",{},"missing CRS",": ",[52,4614,4089],{},[52,4616,4093],{},[26,4618,4619,4622],{},[4609,4620,4621],{},"incorrect CRS",": a CRS is present, but it does not match the actual coordinates",[16,4624,4625],{},"A missing CRS prevents safe reprojection. An incorrect CRS is worse because reprojection will run, but the output will be wrong.",[397,4627,4629],{"id":4628},"code-example-read-a-shapefile-and-inspect-its-crs","Code example: read a shapefile and inspect its CRS",[79,4631,4633],{"className":81,"code":4632,"language":83,"meta":84,"style":84},"import geopandas as gpd\n\ngdf = gpd.read_file(\"data\u002Fcity_boundary.shp\")\n\nprint(\"Current CRS:\", gdf.crs)\nprint(gdf.head())\n",[52,4634,4635,4645,4649,4672,4676,4699],{"__ignoreMap":84},[88,4636,4637,4639,4641,4643],{"class":90,"line":91},[88,4638,95],{"class":94},[88,4640,99],{"class":98},[88,4642,102],{"class":94},[88,4644,105],{"class":98},[88,4646,4647],{"class":90,"line":108},[88,4648,126],{"emptyLinePlaceholder":125},[88,4650,4651,4653,4655,4657,4659,4661,4663,4665,4668,4670],{"class":90,"line":122},[88,4652,132],{"class":98},[88,4654,136],{"class":135},[88,4656,139],{"class":98},[88,4658,143],{"class":142},[88,4660,147],{"class":146},[88,4662,150],{"class":142},[88,4664,154],{"class":153},[88,4666,4667],{"class":157},"data\u002Fcity_boundary.shp",[88,4669,154],{"class":153},[88,4671,163],{"class":142},[88,4673,4674],{"class":90,"line":129},[88,4675,126],{"emptyLinePlaceholder":125},[88,4677,4678,4680,4682,4684,4687,4689,4691,4693,4695,4697],{"class":90,"line":166},[88,4679,454],{"class":453},[88,4681,150],{"class":142},[88,4683,154],{"class":153},[88,4685,4686],{"class":157},"Current CRS:",[88,4688,154],{"class":153},[88,4690,212],{"class":142},[88,4692,228],{"class":146},[88,4694,143],{"class":142},[88,4696,463],{"class":187},[88,4698,163],{"class":142},[88,4700,4701,4703,4705,4707,4709,4711],{"class":90,"line":171},[88,4702,454],{"class":453},[88,4704,150],{"class":142},[88,4706,182],{"class":146},[88,4708,143],{"class":142},[88,4710,699],{"class":146},[88,4712,702],{"class":142},[16,4714,4715],{},"Use this as the first check any time you work with a new shapefile or GeoJSON file.",[397,4717,4719],{"id":4718},"set-the-crs-if-it-is-missing","Set the CRS if it is missing",[16,4721,383,4722,4725],{},[52,4723,4724],{},".set_crs()"," only when the coordinates are already in a known CRS but the metadata is missing.",[16,4727,4728,4729,4090,4731,4733,4734,143],{},"For example, if coordinates are longitude and latitude in WGS84, but ",[52,4730,4089],{},[52,4732,4093],{},", assign ",[52,4735,4125],{},[79,4737,4739],{"className":81,"code":4738,"language":83,"meta":84,"style":84},"if gdf.crs is None:\n    gdf = gdf.set_crs(epsg=4326)\n",[52,4740,4741,4761],{"__ignoreMap":84},[88,4742,4743,4745,4747,4749,4751,4754,4758],{"class":90,"line":91},[88,4744,3871],{"class":94},[88,4746,228],{"class":98},[88,4748,143],{"class":142},[88,4750,463],{"class":187},[88,4752,4753],{"class":135}," is",[88,4755,4757],{"class":4756},"s39Yj"," None",[88,4759,4760],{"class":142},":\n",[88,4762,4763,4766,4768,4770,4772,4774,4776,4778,4780,4783],{"class":90,"line":108},[88,4764,4765],{"class":98},"    gdf ",[88,4767,136],{"class":135},[88,4769,228],{"class":98},[88,4771,143],{"class":142},[88,4773,4118],{"class":146},[88,4775,150],{"class":142},[88,4777,4486],{"class":368},[88,4779,136],{"class":135},[88,4781,4782],{"class":822},"4326",[88,4784,163],{"class":142},[16,4786,4787,4788,4791],{},"This does ",[4609,4789,4790],{},"not"," change coordinate values. It only labels what the existing coordinates mean.",[397,4793,4795,4796],{"id":4794},"code-example-assign-a-missing-crs-with-set_crs","Code example: assign a missing CRS with ",[52,4797,4284],{},[79,4799,4801],{"className":81,"code":4800,"language":83,"meta":84,"style":84},"import geopandas as gpd\nfrom shapely.geometry import Point\n\ngdf = gpd.GeoDataFrame(\n    {\"name\": [\"A\", \"B\"]},\n    geometry=[Point(-73.9857, 40.7484), Point(-73.9819, 40.7681)]\n)\n\nprint(\"Before:\", gdf.crs)\n\ngdf = gdf.set_crs(epsg=4326)\n\nprint(\"After:\", gdf.crs)\n",[52,4802,4803,4813,4829,4833,4848,4882,4928,4932,4936,4959,4963,4985,4989],{"__ignoreMap":84},[88,4804,4805,4807,4809,4811],{"class":90,"line":91},[88,4806,95],{"class":94},[88,4808,99],{"class":98},[88,4810,102],{"class":94},[88,4812,105],{"class":98},[88,4814,4815,4817,4819,4821,4824,4826],{"class":90,"line":108},[88,4816,111],{"class":94},[88,4818,728],{"class":98},[88,4820,143],{"class":142},[88,4822,4823],{"class":98},"geometry ",[88,4825,95],{"class":94},[88,4827,4828],{"class":98}," Point\n",[88,4830,4831],{"class":90,"line":122},[88,4832,126],{"emptyLinePlaceholder":125},[88,4834,4835,4837,4839,4841,4843,4845],{"class":90,"line":129},[88,4836,132],{"class":98},[88,4838,136],{"class":135},[88,4840,139],{"class":98},[88,4842,143],{"class":142},[88,4844,2781],{"class":146},[88,4846,4847],{"class":142},"(\n",[88,4849,4850,4853,4855,4857,4859,4861,4863,4865,4868,4870,4872,4874,4877,4879],{"class":90,"line":166},[88,4851,4852],{"class":142},"    {",[88,4854,154],{"class":153},[88,4856,482],{"class":157},[88,4858,154],{"class":153},[88,4860,4594],{"class":142},[88,4862,1449],{"class":142},[88,4864,154],{"class":153},[88,4866,4867],{"class":157},"A",[88,4869,154],{"class":153},[88,4871,212],{"class":142},[88,4873,215],{"class":153},[88,4875,4876],{"class":157},"B",[88,4878,154],{"class":153},[88,4880,4881],{"class":142},"]},\n",[88,4883,4884,4887,4889,4891,4894,4896,4899,4902,4904,4907,4910,4913,4915,4917,4920,4922,4925],{"class":90,"line":171},[88,4885,4886],{"class":368},"    geometry",[88,4888,136],{"class":135},[88,4890,206],{"class":142},[88,4892,4893],{"class":146},"Point",[88,4895,150],{"class":142},[88,4897,4898],{"class":135},"-",[88,4900,4901],{"class":822},"73.9857",[88,4903,212],{"class":142},[88,4905,4906],{"class":822}," 40.7484",[88,4908,4909],{"class":142},"),",[88,4911,4912],{"class":146}," Point",[88,4914,150],{"class":142},[88,4916,4898],{"class":135},[88,4918,4919],{"class":822},"73.9819",[88,4921,212],{"class":142},[88,4923,4924],{"class":822}," 40.7681",[88,4926,4927],{"class":142},")]\n",[88,4929,4930],{"class":90,"line":196},[88,4931,163],{"class":142},[88,4933,4934],{"class":90,"line":260},[88,4935,126],{"emptyLinePlaceholder":125},[88,4937,4938,4940,4942,4944,4947,4949,4951,4953,4955,4957],{"class":90,"line":265},[88,4939,454],{"class":453},[88,4941,150],{"class":142},[88,4943,154],{"class":153},[88,4945,4946],{"class":157},"Before:",[88,4948,154],{"class":153},[88,4950,212],{"class":142},[88,4952,228],{"class":146},[88,4954,143],{"class":142},[88,4956,463],{"class":187},[88,4958,163],{"class":142},[88,4960,4961],{"class":90,"line":290},[88,4962,126],{"emptyLinePlaceholder":125},[88,4964,4965,4967,4969,4971,4973,4975,4977,4979,4981,4983],{"class":90,"line":318},[88,4966,132],{"class":98},[88,4968,136],{"class":135},[88,4970,228],{"class":98},[88,4972,143],{"class":142},[88,4974,4118],{"class":146},[88,4976,150],{"class":142},[88,4978,4486],{"class":368},[88,4980,136],{"class":135},[88,4982,4782],{"class":822},[88,4984,163],{"class":142},[88,4986,4987],{"class":90,"line":342},[88,4988,126],{"emptyLinePlaceholder":125},[88,4990,4991,4993,4995,4997,5000,5002,5004,5006,5008,5010],{"class":90,"line":347},[88,4992,454],{"class":453},[88,4994,150],{"class":142},[88,4996,154],{"class":153},[88,4998,4999],{"class":157},"After:",[88,5001,154],{"class":153},[88,5003,212],{"class":142},[88,5005,228],{"class":146},[88,5007,143],{"class":142},[88,5009,463],{"class":187},[88,5011,163],{"class":142},[16,5013,5014,5015,5017],{},"Use this only if you know the source coordinates are in ",[52,5016,4125],{},". Do not guess the CRS from coordinates alone.",[397,5019,5021,5022],{"id":5020},"reproject-the-geodataframe-with-to_crs","Reproject the GeoDataFrame with ",[52,5023,537],{},[16,5025,5026,5027,5029],{},"Once the source CRS is correct, use ",[52,5028,4379],{}," to transform the coordinates into a new system.",[397,5031,5033,5034],{"id":5032},"code-example-reproject-to-web-mercator-with-to_crs","Code example: reproject to Web Mercator with ",[52,5035,537],{},[16,5037,5038,5039,5041,5042,5044],{},"A common case is converting from ",[52,5040,4125],{}," to ",[52,5043,4359],{}," for web map display.",[79,5046,5048],{"className":81,"code":5047,"language":83,"meta":84,"style":84},"import geopandas as gpd\n\ngdf = gpd.read_file(\"data\u002Fpoints.geojson\")\n\nprint(\"Source CRS:\", gdf.crs)\n\ngdf_web = gdf.to_crs(epsg=3857)\n\nprint(\"Reprojected CRS:\", gdf_web.crs)\nprint(gdf_web.geometry.head())\n",[52,5049,5050,5060,5064,5087,5091,5114,5118,5141,5145,5169],{"__ignoreMap":84},[88,5051,5052,5054,5056,5058],{"class":90,"line":91},[88,5053,95],{"class":94},[88,5055,99],{"class":98},[88,5057,102],{"class":94},[88,5059,105],{"class":98},[88,5061,5062],{"class":90,"line":108},[88,5063,126],{"emptyLinePlaceholder":125},[88,5065,5066,5068,5070,5072,5074,5076,5078,5080,5083,5085],{"class":90,"line":122},[88,5067,132],{"class":98},[88,5069,136],{"class":135},[88,5071,139],{"class":98},[88,5073,143],{"class":142},[88,5075,147],{"class":146},[88,5077,150],{"class":142},[88,5079,154],{"class":153},[88,5081,5082],{"class":157},"data\u002Fpoints.geojson",[88,5084,154],{"class":153},[88,5086,163],{"class":142},[88,5088,5089],{"class":90,"line":129},[88,5090,126],{"emptyLinePlaceholder":125},[88,5092,5093,5095,5097,5099,5102,5104,5106,5108,5110,5112],{"class":90,"line":166},[88,5094,454],{"class":453},[88,5096,150],{"class":142},[88,5098,154],{"class":153},[88,5100,5101],{"class":157},"Source CRS:",[88,5103,154],{"class":153},[88,5105,212],{"class":142},[88,5107,228],{"class":146},[88,5109,143],{"class":142},[88,5111,463],{"class":187},[88,5113,163],{"class":142},[88,5115,5116],{"class":90,"line":171},[88,5117,126],{"emptyLinePlaceholder":125},[88,5119,5120,5123,5125,5127,5129,5131,5133,5135,5137,5139],{"class":90,"line":196},[88,5121,5122],{"class":98},"gdf_web ",[88,5124,136],{"class":135},[88,5126,228],{"class":98},[88,5128,143],{"class":142},[88,5130,4481],{"class":146},[88,5132,150],{"class":142},[88,5134,4486],{"class":368},[88,5136,136],{"class":135},[88,5138,4491],{"class":822},[88,5140,163],{"class":142},[88,5142,5143],{"class":90,"line":260},[88,5144,126],{"emptyLinePlaceholder":125},[88,5146,5147,5149,5151,5153,5156,5158,5160,5163,5165,5167],{"class":90,"line":265},[88,5148,454],{"class":453},[88,5150,150],{"class":142},[88,5152,154],{"class":153},[88,5154,5155],{"class":157},"Reprojected CRS:",[88,5157,154],{"class":153},[88,5159,212],{"class":142},[88,5161,5162],{"class":146}," gdf_web",[88,5164,143],{"class":142},[88,5166,463],{"class":187},[88,5168,163],{"class":142},[88,5170,5171,5173,5175,5178,5180,5182,5184,5186],{"class":90,"line":290},[88,5172,454],{"class":453},[88,5174,150],{"class":142},[88,5176,5177],{"class":146},"gdf_web",[88,5179,143],{"class":142},[88,5181,188],{"class":187},[88,5183,143],{"class":142},[88,5185,699],{"class":146},[88,5187,702],{"class":142},[16,5189,5190,5191,5193,5194,1266],{},"This transforms the geometry coordinates from geographic coordinates (typically degrees in ",[52,5192,4125],{},") to projected coordinates in meters in Web Mercator (",[52,5195,4359],{},[16,5197,383,5198,5200],{},[52,5199,4359],{}," for display, not for accurate area or distance calculations.",[16,5202,5203],{},"Common target CRS choices:",[23,5205,5206,5211,5214],{},[26,5207,5208,5210],{},[52,5209,4359],{}," for web mapping",[26,5212,5213],{},"local UTM zones for measurement",[26,5215,5216],{},"national projected CRS for local or regional analysis",[397,5218,5220],{"id":5219},"code-example-reproject-to-a-projected-crs-for-area-or-distance-analysis","Code example: reproject to a projected CRS for area or distance analysis",[16,5222,5223,5224,143],{},"For area and distance work, use a projected CRS instead of ",[52,5225,4125],{},[79,5227,5229],{"className":81,"code":5228,"language":83,"meta":84,"style":84},"import geopandas as gpd\n\ngdf = gpd.read_file(\"data\u002Fparcels.geojson\")\n\n# Example: UTM zone 18N\ngdf_utm = gdf.to_crs(epsg=32618)\n\ngdf_utm[\"area_sqm\"] = gdf_utm.area\nprint(gdf_utm[[\"area_sqm\"]].head())\n",[52,5230,5231,5241,5245,5267,5271,5277,5301,5305,5331],{"__ignoreMap":84},[88,5232,5233,5235,5237,5239],{"class":90,"line":91},[88,5234,95],{"class":94},[88,5236,99],{"class":98},[88,5238,102],{"class":94},[88,5240,105],{"class":98},[88,5242,5243],{"class":90,"line":108},[88,5244,126],{"emptyLinePlaceholder":125},[88,5246,5247,5249,5251,5253,5255,5257,5259,5261,5263,5265],{"class":90,"line":122},[88,5248,132],{"class":98},[88,5250,136],{"class":135},[88,5252,139],{"class":98},[88,5254,143],{"class":142},[88,5256,147],{"class":146},[88,5258,150],{"class":142},[88,5260,154],{"class":153},[88,5262,527],{"class":157},[88,5264,154],{"class":153},[88,5266,163],{"class":142},[88,5268,5269],{"class":90,"line":129},[88,5270,126],{"emptyLinePlaceholder":125},[88,5272,5273],{"class":90,"line":166},[88,5274,5276],{"class":5275},"sutJx","# Example: UTM zone 18N\n",[88,5278,5279,5282,5284,5286,5288,5290,5292,5294,5296,5299],{"class":90,"line":171},[88,5280,5281],{"class":98},"gdf_utm ",[88,5283,136],{"class":135},[88,5285,228],{"class":98},[88,5287,143],{"class":142},[88,5289,4481],{"class":146},[88,5291,150],{"class":142},[88,5293,4486],{"class":368},[88,5295,136],{"class":135},[88,5297,5298],{"class":822},"32618",[88,5300,163],{"class":142},[88,5302,5303],{"class":90,"line":196},[88,5304,126],{"emptyLinePlaceholder":125},[88,5306,5307,5310,5312,5314,5317,5319,5321,5323,5326,5328],{"class":90,"line":260},[88,5308,5309],{"class":98},"gdf_utm",[88,5311,206],{"class":142},[88,5313,154],{"class":153},[88,5315,5316],{"class":157},"area_sqm",[88,5318,154],{"class":153},[88,5320,222],{"class":142},[88,5322,225],{"class":135},[88,5324,5325],{"class":98}," gdf_utm",[88,5327,143],{"class":142},[88,5329,5330],{"class":187},"area\n",[88,5332,5333,5335,5337,5339,5341,5343,5345,5347,5349,5351],{"class":90,"line":265},[88,5334,454],{"class":453},[88,5336,150],{"class":142},[88,5338,5309],{"class":146},[88,5340,679],{"class":142},[88,5342,154],{"class":153},[88,5344,5316],{"class":157},[88,5346,154],{"class":153},[88,5348,696],{"class":142},[88,5350,699],{"class":146},[88,5352,702],{"class":142},[16,5354,5355],{},"If your data is in a different location, choose the appropriate UTM zone or another suitable local projected CRS.",[397,5357,5359],{"id":5358},"save-the-reprojected-data","Save the reprojected data",[16,5361,5362],{},"After reprojection, save the output to a new file.",[397,5364,5366],{"id":5365},"code-example-save-the-reprojected-output","Code example: save the reprojected output",[79,5368,5370],{"className":81,"code":5369,"language":83,"meta":84,"style":84},"import geopandas as gpd\n\ngdf = gpd.read_file(\"data\u002Froads.shp\")\ngdf_3857 = gdf.to_crs(epsg=3857)\n\ngdf_3857.to_file(\"output\u002Froads_3857.shp\")\n",[52,5371,5372,5382,5386,5408,5430,5434],{"__ignoreMap":84},[88,5373,5374,5376,5378,5380],{"class":90,"line":91},[88,5375,95],{"class":94},[88,5377,99],{"class":98},[88,5379,102],{"class":94},[88,5381,105],{"class":98},[88,5383,5384],{"class":90,"line":108},[88,5385,126],{"emptyLinePlaceholder":125},[88,5387,5388,5390,5392,5394,5396,5398,5400,5402,5404,5406],{"class":90,"line":122},[88,5389,132],{"class":98},[88,5391,136],{"class":135},[88,5393,139],{"class":98},[88,5395,143],{"class":142},[88,5397,147],{"class":146},[88,5399,150],{"class":142},[88,5401,154],{"class":153},[88,5403,2831],{"class":157},[88,5405,154],{"class":153},[88,5407,163],{"class":142},[88,5409,5410,5412,5414,5416,5418,5420,5422,5424,5426,5428],{"class":90,"line":129},[88,5411,4472],{"class":98},[88,5413,136],{"class":135},[88,5415,228],{"class":98},[88,5417,143],{"class":142},[88,5419,4481],{"class":146},[88,5421,150],{"class":142},[88,5423,4486],{"class":368},[88,5425,136],{"class":135},[88,5427,4491],{"class":822},[88,5429,163],{"class":142},[88,5431,5432],{"class":90,"line":166},[88,5433,126],{"emptyLinePlaceholder":125},[88,5435,5436,5438,5440,5442,5444,5446,5449,5451],{"class":90,"line":171},[88,5437,4502],{"class":98},[88,5439,143],{"class":142},[88,5441,354],{"class":146},[88,5443,150],{"class":142},[88,5445,154],{"class":153},[88,5447,5448],{"class":157},"output\u002Froads_3857.shp",[88,5450,154],{"class":153},[88,5452,163],{"class":142},[16,5454,5455],{},"You can also save to GeoJSON or GeoPackage:",[79,5457,5459],{"className":81,"code":5458,"language":83,"meta":84,"style":84},"gdf_3857.to_file(\"output\u002Froads_3857.geojson\", driver=\"GeoJSON\")\ngdf_3857.to_file(\"output\u002Froads_3857.gpkg\", driver=\"GPKG\")\n",[52,5460,5461,5492],{"__ignoreMap":84},[88,5462,5463,5465,5467,5469,5471,5473,5476,5478,5480,5482,5484,5486,5488,5490],{"class":90,"line":91},[88,5464,4502],{"class":98},[88,5466,143],{"class":142},[88,5468,354],{"class":146},[88,5470,150],{"class":142},[88,5472,154],{"class":153},[88,5474,5475],{"class":157},"output\u002Froads_3857.geojson",[88,5477,154],{"class":153},[88,5479,212],{"class":142},[88,5481,369],{"class":368},[88,5483,136],{"class":135},[88,5485,154],{"class":153},[88,5487,1741],{"class":157},[88,5489,154],{"class":153},[88,5491,163],{"class":142},[88,5493,5494,5496,5498,5500,5502,5504,5507,5509,5511,5513,5515,5517,5519,5521],{"class":90,"line":108},[88,5495,4502],{"class":98},[88,5497,143],{"class":142},[88,5499,354],{"class":146},[88,5501,150],{"class":142},[88,5503,154],{"class":153},[88,5505,5506],{"class":157},"output\u002Froads_3857.gpkg",[88,5508,154],{"class":153},[88,5510,212],{"class":142},[88,5512,369],{"class":368},[88,5514,136],{"class":135},[88,5516,154],{"class":153},[88,5518,376],{"class":157},[88,5520,154],{"class":153},[88,5522,163],{"class":142},[16,5524,5525],{},"Verify the saved CRS by reading the file again:",[79,5527,5529],{"className":81,"code":5528,"language":83,"meta":84,"style":84},"check = gpd.read_file(\"output\u002Froads_3857.gpkg\")\nprint(check.crs)\n",[52,5530,5531,5554],{"__ignoreMap":84},[88,5532,5533,5536,5538,5540,5542,5544,5546,5548,5550,5552],{"class":90,"line":91},[88,5534,5535],{"class":98},"check ",[88,5537,136],{"class":135},[88,5539,139],{"class":98},[88,5541,143],{"class":142},[88,5543,147],{"class":146},[88,5545,150],{"class":142},[88,5547,154],{"class":153},[88,5549,5506],{"class":157},[88,5551,154],{"class":153},[88,5553,163],{"class":142},[88,5555,5556,5558,5560,5563,5565,5567],{"class":90,"line":108},[88,5557,454],{"class":453},[88,5559,150],{"class":142},[88,5561,5562],{"class":146},"check",[88,5564,143],{"class":142},[88,5566,463],{"class":187},[88,5568,163],{"class":142},[11,5570,1782],{"id":1781},[397,5572,5574],{"id":5573},"reproject-in-one-short-workflow","Reproject in one short workflow",[79,5576,5578],{"className":81,"code":5577,"language":83,"meta":84,"style":84},"import geopandas as gpd\n\ngdf = gpd.read_file(\"data\u002Fbuildings.geojson\")\n\nif gdf.crs is None:\n    gdf = gdf.set_crs(epsg=4326)\n\ngdf_projected = gdf.to_crs(epsg=32618)\ngdf_projected.to_file(\"output\u002Fbuildings_32618.gpkg\", driver=\"GPKG\")\n",[52,5579,5580,5590,5594,5617,5621,5637,5659,5663,5686],{"__ignoreMap":84},[88,5581,5582,5584,5586,5588],{"class":90,"line":91},[88,5583,95],{"class":94},[88,5585,99],{"class":98},[88,5587,102],{"class":94},[88,5589,105],{"class":98},[88,5591,5592],{"class":90,"line":108},[88,5593,126],{"emptyLinePlaceholder":125},[88,5595,5596,5598,5600,5602,5604,5606,5608,5610,5613,5615],{"class":90,"line":122},[88,5597,132],{"class":98},[88,5599,136],{"class":135},[88,5601,139],{"class":98},[88,5603,143],{"class":142},[88,5605,147],{"class":146},[88,5607,150],{"class":142},[88,5609,154],{"class":153},[88,5611,5612],{"class":157},"data\u002Fbuildings.geojson",[88,5614,154],{"class":153},[88,5616,163],{"class":142},[88,5618,5619],{"class":90,"line":129},[88,5620,126],{"emptyLinePlaceholder":125},[88,5622,5623,5625,5627,5629,5631,5633,5635],{"class":90,"line":166},[88,5624,3871],{"class":94},[88,5626,228],{"class":98},[88,5628,143],{"class":142},[88,5630,463],{"class":187},[88,5632,4753],{"class":135},[88,5634,4757],{"class":4756},[88,5636,4760],{"class":142},[88,5638,5639,5641,5643,5645,5647,5649,5651,5653,5655,5657],{"class":90,"line":171},[88,5640,4765],{"class":98},[88,5642,136],{"class":135},[88,5644,228],{"class":98},[88,5646,143],{"class":142},[88,5648,4118],{"class":146},[88,5650,150],{"class":142},[88,5652,4486],{"class":368},[88,5654,136],{"class":135},[88,5656,4782],{"class":822},[88,5658,163],{"class":142},[88,5660,5661],{"class":90,"line":196},[88,5662,126],{"emptyLinePlaceholder":125},[88,5664,5665,5668,5670,5672,5674,5676,5678,5680,5682,5684],{"class":90,"line":260},[88,5666,5667],{"class":98},"gdf_projected ",[88,5669,136],{"class":135},[88,5671,228],{"class":98},[88,5673,143],{"class":142},[88,5675,4481],{"class":146},[88,5677,150],{"class":142},[88,5679,4486],{"class":368},[88,5681,136],{"class":135},[88,5683,5298],{"class":822},[88,5685,163],{"class":142},[88,5687,5688,5691,5693,5695,5697,5699,5702,5704,5706,5708,5710,5712,5714,5716],{"class":90,"line":265},[88,5689,5690],{"class":98},"gdf_projected",[88,5692,143],{"class":142},[88,5694,354],{"class":146},[88,5696,150],{"class":142},[88,5698,154],{"class":153},[88,5700,5701],{"class":157},"output\u002Fbuildings_32618.gpkg",[88,5703,154],{"class":153},[88,5705,212],{"class":142},[88,5707,369],{"class":368},[88,5709,136],{"class":135},[88,5711,154],{"class":153},[88,5713,376],{"class":157},[88,5715,154],{"class":153},[88,5717,163],{"class":142},[397,5719,5721],{"id":5720},"match-one-layer-to-another-layers-crs","Match one layer to another layer's CRS",[16,5723,5724],{},"This is common before overlay, clipping, or spatial joins.",[79,5726,5728],{"className":81,"code":5727,"language":83,"meta":84,"style":84},"import geopandas as gpd\n\nparcels = gpd.read_file(\"data\u002Fparcels.gpkg\")\nzoning = gpd.read_file(\"data\u002Fzoning.gpkg\")\n\nzoning = zoning.to_crs(parcels.crs)\n\nprint(\"Parcels CRS:\", parcels.crs)\nprint(\"Zoning CRS:\", zoning.crs)\n",[52,5729,5730,5740,5744,5768,5792,5796,5820,5824,5848],{"__ignoreMap":84},[88,5731,5732,5734,5736,5738],{"class":90,"line":91},[88,5733,95],{"class":94},[88,5735,99],{"class":98},[88,5737,102],{"class":94},[88,5739,105],{"class":98},[88,5741,5742],{"class":90,"line":108},[88,5743,126],{"emptyLinePlaceholder":125},[88,5745,5746,5749,5751,5753,5755,5757,5759,5761,5764,5766],{"class":90,"line":122},[88,5747,5748],{"class":98},"parcels ",[88,5750,136],{"class":135},[88,5752,139],{"class":98},[88,5754,143],{"class":142},[88,5756,147],{"class":146},[88,5758,150],{"class":142},[88,5760,154],{"class":153},[88,5762,5763],{"class":157},"data\u002Fparcels.gpkg",[88,5765,154],{"class":153},[88,5767,163],{"class":142},[88,5769,5770,5773,5775,5777,5779,5781,5783,5785,5788,5790],{"class":90,"line":129},[88,5771,5772],{"class":98},"zoning ",[88,5774,136],{"class":135},[88,5776,139],{"class":98},[88,5778,143],{"class":142},[88,5780,147],{"class":146},[88,5782,150],{"class":142},[88,5784,154],{"class":153},[88,5786,5787],{"class":157},"data\u002Fzoning.gpkg",[88,5789,154],{"class":153},[88,5791,163],{"class":142},[88,5793,5794],{"class":90,"line":166},[88,5795,126],{"emptyLinePlaceholder":125},[88,5797,5798,5800,5802,5805,5807,5809,5811,5814,5816,5818],{"class":90,"line":171},[88,5799,5772],{"class":98},[88,5801,136],{"class":135},[88,5803,5804],{"class":98}," zoning",[88,5806,143],{"class":142},[88,5808,4481],{"class":146},[88,5810,150],{"class":142},[88,5812,5813],{"class":146},"parcels",[88,5815,143],{"class":142},[88,5817,463],{"class":187},[88,5819,163],{"class":142},[88,5821,5822],{"class":90,"line":196},[88,5823,126],{"emptyLinePlaceholder":125},[88,5825,5826,5828,5830,5832,5835,5837,5839,5842,5844,5846],{"class":90,"line":260},[88,5827,454],{"class":453},[88,5829,150],{"class":142},[88,5831,154],{"class":153},[88,5833,5834],{"class":157},"Parcels CRS:",[88,5836,154],{"class":153},[88,5838,212],{"class":142},[88,5840,5841],{"class":146}," parcels",[88,5843,143],{"class":142},[88,5845,463],{"class":187},[88,5847,163],{"class":142},[88,5849,5850,5852,5854,5856,5859,5861,5863,5865,5867,5869],{"class":90,"line":265},[88,5851,454],{"class":453},[88,5853,150],{"class":142},[88,5855,154],{"class":153},[88,5857,5858],{"class":157},"Zoning CRS:",[88,5860,154],{"class":153},[88,5862,212],{"class":142},[88,5864,5804],{"class":146},[88,5866,143],{"class":142},[88,5868,463],{"class":187},[88,5870,163],{"class":142},[11,5872,2483],{"id":2482},[397,5874,5876,5878,5879],{"id":5875},"set_crs-vs-to_crs",[52,5877,4284],{}," vs ",[52,5880,537],{},[16,5882,5883],{},"This is the most important distinction in GeoPandas CRS workflows.",[3052,5885,5886],{"id":4118},[52,5887,4284],{},[16,5889,5890],{},"Use this when the coordinates are already correct, but the CRS label is missing.",[16,5892,5893,5894],{},"It answers: ",[4609,5895,5896],{},"what do these existing coordinates mean?",[79,5898,5900],{"className":81,"code":5899,"language":83,"meta":84,"style":84},"gdf = gdf.set_crs(epsg=4326)\n",[52,5901,5902],{"__ignoreMap":84},[88,5903,5904,5906,5908,5910,5912,5914,5916,5918,5920,5922],{"class":90,"line":91},[88,5905,132],{"class":98},[88,5907,136],{"class":135},[88,5909,228],{"class":98},[88,5911,143],{"class":142},[88,5913,4118],{"class":146},[88,5915,150],{"class":142},[88,5917,4486],{"class":368},[88,5919,136],{"class":135},[88,5921,4782],{"class":822},[88,5923,163],{"class":142},[3052,5925,5926],{"id":4481},[52,5927,537],{},[16,5929,5930],{},"Use this when you want to transform coordinates into a different coordinate system.",[16,5932,5893,5933],{},[4609,5934,5935],{},"convert these coordinates into another CRS",[79,5937,5939],{"className":81,"code":5938,"language":83,"meta":84,"style":84},"gdf_projected = gdf.to_crs(epsg=3857)\n",[52,5940,5941],{"__ignoreMap":84},[88,5942,5943,5945,5947,5949,5951,5953,5955,5957,5959,5961],{"class":90,"line":91},[88,5944,5667],{"class":98},[88,5946,136],{"class":135},[88,5948,228],{"class":98},[88,5950,143],{"class":142},[88,5952,4481],{"class":146},[88,5954,150],{"class":142},[88,5956,4486],{"class":368},[88,5958,136],{"class":135},[88,5960,4491],{"class":822},[88,5962,163],{"class":142},[16,5964,5965,5966,5968,5969,5971,5972,5974],{},"If you use ",[52,5967,4284],{}," when you meant ",[52,5970,537],{},", your layer will not actually move into a new coordinate system. If you use ",[52,5973,537],{}," on data with a wrong or missing CRS, the output will be incorrect.",[397,5976,5978],{"id":5977},"choosing-the-right-target-crs","Choosing the right target CRS",[16,5980,5981,5983],{},[52,5982,4125],{}," is common for storage and exchange, especially with GeoJSON, but it is not a good choice for measurement because coordinates are stored in degrees.",[16,5985,5986],{},"Use a projected CRS when you need:",[23,5988,5989,5992,5995,5998,6001],{},[26,5990,5991],{},"distance",[26,5993,5994],{},"area",[26,5996,5997],{},"length",[26,5999,6000],{},"buffers",[26,6002,6003],{},"overlay analysis based on local accuracy",[16,6005,6006],{},"Examples:",[23,6008,6009,6014,6021],{},[26,6010,6011,6013],{},[52,6012,4359],{}," for web display",[26,6015,6016,6017,6020],{},"UTM CRS such as ",[52,6018,6019],{},"EPSG:32618"," for local metric analysis",[26,6022,6023],{},"a national CRS for country-specific workflows",[16,6025,6026],{},"The correct CRS depends on where the data is located and what you need to do with it.",[397,6028,6030],{"id":6029},"why-layers-fail-to-align","Why layers fail to align",[16,6032,6033],{},"A mismatched CRS is one of the most common reasons layers do not line up.",[16,6035,6036],{},"Other causes include:",[23,6038,6039,6042,6047,6050],{},[26,6040,6041],{},"one layer has no CRS metadata",[26,6043,6044,6045],{},"the wrong CRS was assigned with ",[52,6046,4284],{},[26,6048,6049],{},"data was exported without correct CRS information",[26,6051,6052],{},"axis order confusion in some external workflows",[16,6054,6055],{},"Before overlay, join, clip, or measurement, make sure both layers use appropriate and matching CRS.",[11,6057,6059],{"id":6058},"edge-cases-notes","Edge cases \u002F notes",[397,6061,6063],{"id":6062},"notes-and-common-mistakes","Notes and common mistakes",[23,6065,6066,6073,6076,6081,6084,6087,6090,6093],{},[26,6067,6068,6069,4090,6071],{},"reprojection fails if ",[52,6070,4089],{},[52,6072,4093],{},[26,6074,6075],{},"assigning the wrong CRS can produce bad output even when the code runs",[26,6077,6078,6079],{},"GeoJSON is commonly used with ",[52,6080,4125],{},[26,6082,6083],{},"GeoPackage usually preserves CRS metadata more reliably than shapefile",[26,6085,6086],{},"shapefiles have format limitations, so GeoPackage is often a better output format for practical workflows",[26,6088,6089],{},"large datasets can take longer to transform",[26,6091,6092],{},"reproject both layers before spatial joins, overlays, clipping, or measurements",[26,6094,6095],{},"invalid geometries can cause problems in later analysis, even if reprojection itself succeeds",[16,6097,6098],{},"A simple geometry check:",[79,6100,6102],{"className":81,"code":6101,"language":83,"meta":84,"style":84},"invalid = ~gdf.is_valid\nprint(gdf[invalid])\n",[52,6103,6104,6119],{"__ignoreMap":84},[88,6105,6106,6109,6111,6113,6115,6117],{"class":90,"line":91},[88,6107,6108],{"class":98},"invalid ",[88,6110,136],{"class":135},[88,6112,179],{"class":135},[88,6114,182],{"class":98},[88,6116,143],{"class":142},[88,6118,193],{"class":187},[88,6120,6121,6123,6125,6127,6129,6132],{"class":90,"line":108},[88,6122,454],{"class":453},[88,6124,150],{"class":142},[88,6126,182],{"class":146},[88,6128,206],{"class":142},[88,6130,6131],{"class":146},"invalid",[88,6133,2076],{"class":142},[16,6135,6136],{},"If needed, repair invalid geometries before more complex processing.",[11,6138,2612],{"id":2611},[16,6140,6141,6142,143],{},"If you need background on coordinate systems, see ",[2617,6143,6145],{"href":6144},"\u002Ffoundation\u002Fcrs-coordinate-systems-explained\u002F","Coordinate Reference Systems (CRS) in Python GIS",[16,6147,6148],{},"For related tasks, see:",[23,6150,6151,6155],{},[26,6152,6153],{},[2617,6154,2631],{"href":2630},[26,6156,6157],{},[2617,6158,4209],{"href":4208},[16,6160,6161,6162,143],{},"If you need to export the result, see ",[2617,6163,2637],{"href":2636},[16,6165,6166,6167,143],{},"If your data still does not line up, check ",[2617,6168,6170],{"href":6169},"\u002Ftroubleshooting\u002Ffix-crs-mismatch-geopandas\u002F","Why GeoPandas Layers Do Not Align on a Map",[11,6172,2647],{"id":2646},[397,6174,6176],{"id":6175},"how-do-i-reproject-a-geodataframe-in-python-with-geopandas","How do I reproject a GeoDataFrame in Python with GeoPandas?",[16,6178,383,6179,6181,6182,6184],{},[52,6180,4402],{}," after confirming that ",[52,6183,4089],{}," is already set correctly.",[79,6186,6188],{"className":81,"code":6187,"language":83,"meta":84,"style":84},"gdf = gdf.to_crs(epsg=3857)\n",[52,6189,6190],{"__ignoreMap":84},[88,6191,6192,6194,6196,6198,6200,6202,6204,6206,6208,6210],{"class":90,"line":91},[88,6193,132],{"class":98},[88,6195,136],{"class":135},[88,6197,228],{"class":98},[88,6199,143],{"class":142},[88,6201,4481],{"class":146},[88,6203,150],{"class":142},[88,6205,4486],{"class":368},[88,6207,136],{"class":135},[88,6209,4491],{"class":822},[88,6211,163],{"class":142},[397,6213,6215,6216,2864,6218,6220],{"id":6214},"what-is-the-difference-between-set_crs-and-to_crs-in-geopandas","What is the difference between ",[52,6217,4284],{},[52,6219,537],{}," in GeoPandas?",[16,6222,6223,6225,6226,6229,6231],{},[52,6224,4284],{}," assigns CRS metadata without changing coordinates.",[6227,6228],"br",{},[52,6230,537],{}," transforms coordinates into a different coordinate system.",[397,6233,6235],{"id":6234},"why-does-reprojection-fail-when-my-geodataframe-has-no-crs","Why does reprojection fail when my GeoDataFrame has no CRS?",[16,6237,6238],{},"GeoPandas cannot transform coordinates if it does not know the source coordinate system. Set the CRS first if it is known:",[79,6240,6241],{"className":81,"code":5899,"language":83,"meta":84,"style":84},[52,6242,6243],{"__ignoreMap":84},[88,6244,6245,6247,6249,6251,6253,6255,6257,6259,6261,6263],{"class":90,"line":91},[88,6246,132],{"class":98},[88,6248,136],{"class":135},[88,6250,228],{"class":98},[88,6252,143],{"class":142},[88,6254,4118],{"class":146},[88,6256,150],{"class":142},[88,6258,4486],{"class":368},[88,6260,136],{"class":135},[88,6262,4782],{"class":822},[88,6264,163],{"class":142},[397,6266,6268],{"id":6267},"which-crs-should-i-use-for-distance-or-area-calculations-in-geopandas","Which CRS should I use for distance or area calculations in GeoPandas?",[16,6270,6271,6272,6274],{},"Use a projected CRS, such as a local UTM zone or national projected CRS. Do not use ",[52,6273,4125],{}," for area or distance calculations.",[2693,6276,6277],{},"html pre.shiki code .sVHd0, html code.shiki .sVHd0{--shiki-light:#39ADB5;--shiki-light-font-style:italic;--shiki-default:#D73A49;--shiki-default-font-style:inherit;--shiki-dark:#F97583;--shiki-dark-font-style:inherit}html pre.shiki code .su5hD, html code.shiki .su5hD{--shiki-light:#90A4AE;--shiki-default:#24292E;--shiki-dark:#E1E4E8}html pre.shiki code .smGrS, html code.shiki .smGrS{--shiki-light:#39ADB5;--shiki-default:#D73A49;--shiki-dark:#F97583}html pre.shiki code .sP7_E, html code.shiki .sP7_E{--shiki-light:#39ADB5;--shiki-default:#24292E;--shiki-dark:#E1E4E8}html pre.shiki code .slqww, html code.shiki .slqww{--shiki-light:#6182B8;--shiki-default:#24292E;--shiki-dark:#E1E4E8}html pre.shiki code .sjJ54, html code.shiki .sjJ54{--shiki-light:#39ADB5;--shiki-default:#032F62;--shiki-dark:#9ECBFF}html pre.shiki code .s_sjI, html code.shiki .s_sjI{--shiki-light:#91B859;--shiki-default:#032F62;--shiki-dark:#9ECBFF}html pre.shiki code .sptTA, html code.shiki .sptTA{--shiki-light:#6182B8;--shiki-default:#005CC5;--shiki-dark:#79B8FF}html pre.shiki code .skxfh, html code.shiki .skxfh{--shiki-light:#E53935;--shiki-default:#24292E;--shiki-dark:#E1E4E8}html pre.shiki code .s99_P, html code.shiki .s99_P{--shiki-light:#90A4AE;--shiki-light-font-style:italic;--shiki-default:#E36209;--shiki-default-font-style:inherit;--shiki-dark:#FFAB70;--shiki-dark-font-style:inherit}html pre.shiki code .srdBf, html code.shiki .srdBf{--shiki-light:#F76D47;--shiki-default:#005CC5;--shiki-dark:#79B8FF}html .light .shiki span {color: var(--shiki-light);background: var(--shiki-light-bg);font-style: var(--shiki-light-font-style);font-weight: var(--shiki-light-font-weight);text-decoration: var(--shiki-light-text-decoration);}html.light .shiki span {color: var(--shiki-light);background: var(--shiki-light-bg);font-style: var(--shiki-light-font-style);font-weight: var(--shiki-light-font-weight);text-decoration: var(--shiki-light-text-decoration);}html .default .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html.dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html pre.shiki code .s_hVV, html code.shiki .s_hVV{--shiki-light:#90A4AE;--shiki-default:#005CC5;--shiki-dark:#79B8FF}html pre.shiki code .s39Yj, html code.shiki .s39Yj{--shiki-light:#39ADB5;--shiki-default:#005CC5;--shiki-dark:#79B8FF}html pre.shiki code .sutJx, html code.shiki .sutJx{--shiki-light:#90A4AE;--shiki-light-font-style:italic;--shiki-default:#6A737D;--shiki-default-font-style:inherit;--shiki-dark:#6A737D;--shiki-dark-font-style:inherit}",{"title":84,"searchDepth":108,"depth":108,"links":6279},[6280,6281,6282,6296,6300,6306,6309,6310],{"id":13,"depth":108,"text":14},{"id":73,"depth":108,"text":74},{"id":394,"depth":108,"text":395,"children":6283},[6284,6285,6286,6287,6289,6291,6293,6294,6295],{"id":4519,"depth":122,"text":4520},{"id":4628,"depth":122,"text":4629},{"id":4718,"depth":122,"text":4719},{"id":4794,"depth":122,"text":6288},"Code example: assign a missing CRS with set_crs()",{"id":5020,"depth":122,"text":6290},"Reproject the GeoDataFrame with to_crs()",{"id":5032,"depth":122,"text":6292},"Code example: reproject to Web Mercator with to_crs()",{"id":5219,"depth":122,"text":5220},{"id":5358,"depth":122,"text":5359},{"id":5365,"depth":122,"text":5366},{"id":1781,"depth":108,"text":1782,"children":6297},[6298,6299],{"id":5573,"depth":122,"text":5574},{"id":5720,"depth":122,"text":5721},{"id":2482,"depth":108,"text":2483,"children":6301},[6302,6304,6305],{"id":5875,"depth":122,"text":6303},"set_crs() vs to_crs()",{"id":5977,"depth":122,"text":5978},{"id":6029,"depth":122,"text":6030},{"id":6058,"depth":108,"text":6059,"children":6307},[6308],{"id":6062,"depth":122,"text":6063},{"id":2611,"depth":108,"text":2612},{"id":2646,"depth":108,"text":2647,"children":6311},[6312,6313,6315,6316],{"id":6175,"depth":122,"text":6176},{"id":6214,"depth":122,"text":6314},"What is the difference between set_crs() and to_crs() in GeoPandas?",{"id":6234,"depth":122,"text":6235},{"id":6267,"depth":122,"text":6268},"How to reproject spatial data in Python using GeoPandas to_crs(), with examples for common coordinate systems.",{},"\u002Ftasks\u002Freproject-geodataframe-python",{"title":4205,"description":6317},"tasks\u002Freproject-geodataframe-python","Taus0odmvqpu5bLGgYf31WnnX4sOYQf_LRKFEuxZF_E",{"id":6324,"title":4209,"body":6325,"description":8553,"extension":2741,"meta":8554,"navigation":125,"path":8555,"seo":8556,"stem":8557,"__hash__":8558},"content\u002Ftasks\u002Fspatial-join-python-geopandas.md",{"type":8,"value":6326,"toc":8518},[6327,6329,6332,6335,6349,6363,6366,6368,6374,6562,6565,6567,6571,6574,6673,6679,6684,6688,6691,6732,6735,6746,6752,6756,6759,6792,6795,6823,6826,6830,6833,6850,6853,6870,6873,6911,6914,6918,6924,6990,6993,7012,7015,7019,7022,7037,7070,7073,7077,7080,7116,7119,7174,7177,7179,7183,7186,7416,7420,7423,7561,7568,7572,7575,7804,7807,7811,7814,8061,8063,8066,8076,8083,8086,8097,8100,8103,8117,8120,8122,8126,8129,8132,8146,8149,8153,8156,8191,8194,8223,8227,8230,8303,8306,8310,8313,8330,8336,8340,8343,8346,8360,8362,8368,8371,8381,8387,8389,8393,8399,8450,8461,8478,8484,8488,8491,8505,8508,8512,8515],[11,6328,14],{"id":13},[16,6330,6331],{},"A spatial join lets you transfer attributes from one spatial layer to another based on location instead of a shared ID field.",[16,6333,6334],{},"Typical GIS tasks include:",[23,6336,6337,6340,6343,6346],{},[26,6338,6339],{},"assigning district names to customer points",[26,6341,6342],{},"joining addresses to census tracts",[26,6344,6345],{},"attaching flood zone attributes to parcel polygons",[26,6347,6348],{},"matching building footprints to administrative boundaries",[16,6350,6351,6352,6355,6356,6359,6360,143],{},"In GeoPandas, this means taking two vector layers and joining them using a spatial relationship such as ",[52,6353,6354],{},"intersects",", ",[52,6357,6358],{},"within",", or ",[52,6361,6362],{},"contains",[16,6364,6365],{},"This page focuses only on vector spatial joins with GeoPandas.",[11,6367,74],{"id":73},[16,6369,383,6370,6373],{},[52,6371,6372],{},"geopandas.sjoin()"," with two GeoDataFrames that use the same CRS, then choose the correct spatial predicate for your workflow.",[79,6375,6377],{"className":81,"code":6376,"language":83,"meta":84,"style":84},"import geopandas as gpd\n\npoints = gpd.read_file(\"data\u002Fcustomer_points.geojson\")\npolygons = gpd.read_file(\"data\u002Fcity_districts.gpkg\")\n\nif points.crs != polygons.crs:\n    polygons = polygons.to_crs(points.crs)\n\njoined = gpd.sjoin(points, polygons, how=\"left\", predicate=\"within\")\nprint(joined.head())\n",[52,6378,6379,6389,6393,6417,6441,6445,6468,6492,6496,6547],{"__ignoreMap":84},[88,6380,6381,6383,6385,6387],{"class":90,"line":91},[88,6382,95],{"class":94},[88,6384,99],{"class":98},[88,6386,102],{"class":94},[88,6388,105],{"class":98},[88,6390,6391],{"class":90,"line":108},[88,6392,126],{"emptyLinePlaceholder":125},[88,6394,6395,6398,6400,6402,6404,6406,6408,6410,6413,6415],{"class":90,"line":122},[88,6396,6397],{"class":98},"points ",[88,6399,136],{"class":135},[88,6401,139],{"class":98},[88,6403,143],{"class":142},[88,6405,147],{"class":146},[88,6407,150],{"class":142},[88,6409,154],{"class":153},[88,6411,6412],{"class":157},"data\u002Fcustomer_points.geojson",[88,6414,154],{"class":153},[88,6416,163],{"class":142},[88,6418,6419,6422,6424,6426,6428,6430,6432,6434,6437,6439],{"class":90,"line":129},[88,6420,6421],{"class":98},"polygons ",[88,6423,136],{"class":135},[88,6425,139],{"class":98},[88,6427,143],{"class":142},[88,6429,147],{"class":146},[88,6431,150],{"class":142},[88,6433,154],{"class":153},[88,6435,6436],{"class":157},"data\u002Fcity_districts.gpkg",[88,6438,154],{"class":153},[88,6440,163],{"class":142},[88,6442,6443],{"class":90,"line":166},[88,6444,126],{"emptyLinePlaceholder":125},[88,6446,6447,6449,6452,6454,6456,6459,6462,6464,6466],{"class":90,"line":171},[88,6448,3871],{"class":94},[88,6450,6451],{"class":98}," points",[88,6453,143],{"class":142},[88,6455,463],{"class":187},[88,6457,6458],{"class":135}," !=",[88,6460,6461],{"class":98}," polygons",[88,6463,143],{"class":142},[88,6465,463],{"class":187},[88,6467,4760],{"class":142},[88,6469,6470,6473,6475,6477,6479,6481,6483,6486,6488,6490],{"class":90,"line":196},[88,6471,6472],{"class":98},"    polygons ",[88,6474,136],{"class":135},[88,6476,6461],{"class":98},[88,6478,143],{"class":142},[88,6480,4481],{"class":146},[88,6482,150],{"class":142},[88,6484,6485],{"class":146},"points",[88,6487,143],{"class":142},[88,6489,463],{"class":187},[88,6491,163],{"class":142},[88,6493,6494],{"class":90,"line":260},[88,6495,126],{"emptyLinePlaceholder":125},[88,6497,6498,6501,6503,6505,6507,6510,6512,6514,6516,6518,6520,6523,6525,6527,6530,6532,6534,6537,6539,6541,6543,6545],{"class":90,"line":265},[88,6499,6500],{"class":98},"joined ",[88,6502,136],{"class":135},[88,6504,139],{"class":98},[88,6506,143],{"class":142},[88,6508,6509],{"class":146},"sjoin",[88,6511,150],{"class":142},[88,6513,6485],{"class":146},[88,6515,212],{"class":142},[88,6517,6461],{"class":146},[88,6519,212],{"class":142},[88,6521,6522],{"class":368}," how",[88,6524,136],{"class":135},[88,6526,154],{"class":153},[88,6528,6529],{"class":157},"left",[88,6531,154],{"class":153},[88,6533,212],{"class":142},[88,6535,6536],{"class":368}," predicate",[88,6538,136],{"class":135},[88,6540,154],{"class":153},[88,6542,6358],{"class":157},[88,6544,154],{"class":153},[88,6546,163],{"class":142},[88,6548,6549,6551,6553,6556,6558,6560],{"class":90,"line":290},[88,6550,454],{"class":453},[88,6552,150],{"class":142},[88,6554,6555],{"class":146},"joined",[88,6557,143],{"class":142},[88,6559,699],{"class":146},[88,6561,702],{"class":142},[16,6563,6564],{},"This keeps all points and adds polygon attributes where each point falls within a polygon.",[11,6566,395],{"id":394},[397,6568,6570],{"id":6569},"load-the-two-spatial-layers","Load the two spatial layers",[16,6572,6573],{},"Read both datasets into GeoDataFrames.",[79,6575,6577],{"className":81,"code":6576,"language":83,"meta":84,"style":84},"import geopandas as gpd\n\npoints = gpd.read_file(\"data\u002Fcustomer_points.geojson\")\ndistricts = gpd.read_file(\"data\u002Fcity_districts.shp\")\n\nprint(type(points))\nprint(type(districts))\n",[52,6578,6579,6589,6593,6615,6639,6643,6658],{"__ignoreMap":84},[88,6580,6581,6583,6585,6587],{"class":90,"line":91},[88,6582,95],{"class":94},[88,6584,99],{"class":98},[88,6586,102],{"class":94},[88,6588,105],{"class":98},[88,6590,6591],{"class":90,"line":108},[88,6592,126],{"emptyLinePlaceholder":125},[88,6594,6595,6597,6599,6601,6603,6605,6607,6609,6611,6613],{"class":90,"line":122},[88,6596,6397],{"class":98},[88,6598,136],{"class":135},[88,6600,139],{"class":98},[88,6602,143],{"class":142},[88,6604,147],{"class":146},[88,6606,150],{"class":142},[88,6608,154],{"class":153},[88,6610,6412],{"class":157},[88,6612,154],{"class":153},[88,6614,163],{"class":142},[88,6616,6617,6620,6622,6624,6626,6628,6630,6632,6635,6637],{"class":90,"line":129},[88,6618,6619],{"class":98},"districts ",[88,6621,136],{"class":135},[88,6623,139],{"class":98},[88,6625,143],{"class":142},[88,6627,147],{"class":146},[88,6629,150],{"class":142},[88,6631,154],{"class":153},[88,6633,6634],{"class":157},"data\u002Fcity_districts.shp",[88,6636,154],{"class":153},[88,6638,163],{"class":142},[88,6640,6641],{"class":90,"line":166},[88,6642,126],{"emptyLinePlaceholder":125},[88,6644,6645,6647,6649,6652,6654,6656],{"class":90,"line":171},[88,6646,454],{"class":453},[88,6648,150],{"class":142},[88,6650,6651],{"class":3892},"type",[88,6653,150],{"class":142},[88,6655,6485],{"class":146},[88,6657,500],{"class":142},[88,6659,6660,6662,6664,6666,6668,6671],{"class":90,"line":196},[88,6661,454],{"class":453},[88,6663,150],{"class":142},[88,6665,6651],{"class":3892},[88,6667,150],{"class":142},[88,6669,6670],{"class":146},"districts",[88,6672,500],{"class":142},[16,6674,6675,6676,143],{},"Both objects should be ",[52,6677,6678],{},"geopandas.geodataframe.GeoDataFrame",[16,6680,6681,6682,143],{},"GeoPandas can read shapefiles, GeoJSON, and GeoPackage files with ",[52,6683,4004],{},[397,6685,6687],{"id":6686},"check-geometry-types","Check geometry types",[16,6689,6690],{},"Geometry type affects which spatial predicate makes sense.",[79,6692,6694],{"className":81,"code":6693,"language":83,"meta":84,"style":84},"print(points.geom_type.value_counts())\nprint(districts.geom_type.value_counts())\n",[52,6695,6696,6714],{"__ignoreMap":84},[88,6697,6698,6700,6702,6704,6706,6708,6710,6712],{"class":90,"line":91},[88,6699,454],{"class":453},[88,6701,150],{"class":142},[88,6703,6485],{"class":146},[88,6705,143],{"class":142},[88,6707,1091],{"class":187},[88,6709,143],{"class":142},[88,6711,1096],{"class":146},[88,6713,702],{"class":142},[88,6715,6716,6718,6720,6722,6724,6726,6728,6730],{"class":90,"line":108},[88,6717,454],{"class":453},[88,6719,150],{"class":142},[88,6721,6670],{"class":146},[88,6723,143],{"class":142},[88,6725,1091],{"class":187},[88,6727,143],{"class":142},[88,6729,1096],{"class":146},[88,6731,702],{"class":142},[16,6733,6734],{},"Typical join patterns include:",[23,6736,6737,6740,6743],{},[26,6738,6739],{},"points to polygons",[26,6741,6742],{},"polygons to polygons",[26,6744,6745],{},"lines to polygons",[16,6747,6748,6749,6751],{},"If you want to assign polygon attributes to points, ",[52,6750,6358],{}," is usually the clearest choice.",[397,6753,6755],{"id":6754},"make-sure-both-layers-use-the-same-crs","Make sure both layers use the same CRS",[16,6757,6758],{},"Spatial joins require both layers to use the same coordinate reference system.",[79,6760,6762],{"className":81,"code":6761,"language":83,"meta":84,"style":84},"print(points.crs)\nprint(districts.crs)\n",[52,6763,6764,6778],{"__ignoreMap":84},[88,6765,6766,6768,6770,6772,6774,6776],{"class":90,"line":91},[88,6767,454],{"class":453},[88,6769,150],{"class":142},[88,6771,6485],{"class":146},[88,6773,143],{"class":142},[88,6775,463],{"class":187},[88,6777,163],{"class":142},[88,6779,6780,6782,6784,6786,6788,6790],{"class":90,"line":108},[88,6781,454],{"class":453},[88,6783,150],{"class":142},[88,6785,6670],{"class":146},[88,6787,143],{"class":142},[88,6789,463],{"class":187},[88,6791,163],{"class":142},[16,6793,6794],{},"If they do not match, reproject one layer before joining:",[79,6796,6798],{"className":81,"code":6797,"language":83,"meta":84,"style":84},"districts = districts.to_crs(points.crs)\n",[52,6799,6800],{"__ignoreMap":84},[88,6801,6802,6804,6806,6809,6811,6813,6815,6817,6819,6821],{"class":90,"line":91},[88,6803,6619],{"class":98},[88,6805,136],{"class":135},[88,6807,6808],{"class":98}," districts",[88,6810,143],{"class":142},[88,6812,4481],{"class":146},[88,6814,150],{"class":142},[88,6816,6485],{"class":146},[88,6818,143],{"class":142},[88,6820,463],{"class":187},[88,6822,163],{"class":142},[16,6824,6825],{},"If you skip this step, the join may return no matches or incorrect matches.",[397,6827,6829],{"id":6828},"choose-the-right-spatial-predicate","Choose the right spatial predicate",[16,6831,6832],{},"Common predicates include:",[23,6834,6835,6840,6845],{},[26,6836,6837,6839],{},[52,6838,6354],{},": features touch or overlap in any way",[26,6841,6842,6844],{},[52,6843,6358],{},": left geometry is completely inside right geometry",[26,6846,6847,6849],{},[52,6848,6362],{},": left geometry completely contains right geometry",[16,6851,6852],{},"Common choices:",[23,6854,6855,6860,6865],{},[26,6856,6857,6858],{},"points inside polygons: usually ",[52,6859,6358],{},[26,6861,6862,6863],{},"overlapping polygons: usually ",[52,6864,6354],{},[26,6866,6867,6868],{},"lines crossing polygons: usually ",[52,6869,6354],{},[16,6871,6872],{},"If you want to inspect which predicates are available in your environment, check the spatial index first:",[79,6874,6876],{"className":81,"code":6875,"language":83,"meta":84,"style":84},"if points.has_sindex:\n    print(points.sindex.valid_query_predicates)\n",[52,6877,6878,6891],{"__ignoreMap":84},[88,6879,6880,6882,6884,6886,6889],{"class":90,"line":91},[88,6881,3871],{"class":94},[88,6883,6451],{"class":98},[88,6885,143],{"class":142},[88,6887,6888],{"class":187},"has_sindex",[88,6890,4760],{"class":142},[88,6892,6893,6895,6897,6899,6901,6904,6906,6909],{"class":90,"line":108},[88,6894,2055],{"class":453},[88,6896,150],{"class":142},[88,6898,6485],{"class":146},[88,6900,143],{"class":142},[88,6902,6903],{"class":187},"sindex",[88,6905,143],{"class":142},[88,6907,6908],{"class":187},"valid_query_predicates",[88,6910,163],{"class":142},[16,6912,6913],{},"This depends on your installed spatial index backend, so treat it as a useful check rather than a required step.",[397,6915,6917],{"id":6916},"run-the-spatial-join","Run the spatial join",[16,6919,383,6920,6923],{},[52,6921,6922],{},"gpd.sjoin()"," to join the left layer to the right layer based on geometry.",[79,6925,6927],{"className":81,"code":6926,"language":83,"meta":84,"style":84},"joined = gpd.sjoin(\n    points,\n    districts,\n    how=\"left\",\n    predicate=\"within\"\n)\n",[52,6928,6929,6943,6951,6958,6973,6986],{"__ignoreMap":84},[88,6930,6931,6933,6935,6937,6939,6941],{"class":90,"line":91},[88,6932,6500],{"class":98},[88,6934,136],{"class":135},[88,6936,139],{"class":98},[88,6938,143],{"class":142},[88,6940,6509],{"class":146},[88,6942,4847],{"class":142},[88,6944,6945,6948],{"class":90,"line":108},[88,6946,6947],{"class":146},"    points",[88,6949,6950],{"class":142},",\n",[88,6952,6953,6956],{"class":90,"line":122},[88,6954,6955],{"class":146},"    districts",[88,6957,6950],{"class":142},[88,6959,6960,6963,6965,6967,6969,6971],{"class":90,"line":129},[88,6961,6962],{"class":368},"    how",[88,6964,136],{"class":135},[88,6966,154],{"class":153},[88,6968,6529],{"class":157},[88,6970,154],{"class":153},[88,6972,6950],{"class":142},[88,6974,6975,6978,6980,6982,6984],{"class":90,"line":166},[88,6976,6977],{"class":368},"    predicate",[88,6979,136],{"class":135},[88,6981,154],{"class":153},[88,6983,6358],{"class":157},[88,6985,2997],{"class":153},[88,6987,6988],{"class":90,"line":171},[88,6989,163],{"class":142},[16,6991,6992],{},"Join types:",[23,6994,6995,7000,7006],{},[26,6996,6997,6999],{},[52,6998,6529],{},": keep all rows from the left GeoDataFrame",[26,7001,7002,7005],{},[52,7003,7004],{},"inner",": keep only matched rows",[26,7007,7008,7011],{},[52,7009,7010],{},"right",": available in some workflows, but verify behavior in your GeoPandas version before relying on it",[16,7013,7014],{},"In most point-in-polygon workflows, the left layer is the layer you want to preserve.",[397,7016,7018],{"id":7017},"review-the-output-columns","Review the output columns",[16,7020,7021],{},"The result includes:",[23,7023,7024,7027,7030],{},[26,7025,7026],{},"original columns from the left layer",[26,7028,7029],{},"columns from the right layer, unless you subset the right GeoDataFrame before joining",[26,7031,7032,7033,7036],{},"an ",[52,7034,7035],{},"index_right"," column showing the matched feature index from the right layer",[79,7038,7040],{"className":81,"code":7039,"language":83,"meta":84,"style":84},"print(joined.columns)\nprint(joined.head())\n",[52,7041,7042,7056],{"__ignoreMap":84},[88,7043,7044,7046,7048,7050,7052,7054],{"class":90,"line":91},[88,7045,454],{"class":453},[88,7047,150],{"class":142},[88,7049,6555],{"class":146},[88,7051,143],{"class":142},[88,7053,3096],{"class":187},[88,7055,163],{"class":142},[88,7057,7058,7060,7062,7064,7066,7068],{"class":90,"line":108},[88,7059,454],{"class":453},[88,7061,150],{"class":142},[88,7063,6555],{"class":146},[88,7065,143],{"class":142},[88,7067,699],{"class":146},[88,7069,702],{"class":142},[16,7071,7072],{},"If both layers contain the same column name, GeoPandas adds suffixes to distinguish them.",[397,7074,7076],{"id":7075},"save-the-joined-result","Save the joined result",[16,7078,7079],{},"Export the result to a new file.",[79,7081,7083],{"className":81,"code":7082,"language":83,"meta":84,"style":84},"joined.to_file(\"output\u002Fcustomer_points_with_districts.gpkg\", driver=\"GPKG\")\n",[52,7084,7085],{"__ignoreMap":84},[88,7086,7087,7089,7091,7093,7095,7097,7100,7102,7104,7106,7108,7110,7112,7114],{"class":90,"line":91},[88,7088,6555],{"class":98},[88,7090,143],{"class":142},[88,7092,354],{"class":146},[88,7094,150],{"class":142},[88,7096,154],{"class":153},[88,7098,7099],{"class":157},"output\u002Fcustomer_points_with_districts.gpkg",[88,7101,154],{"class":153},[88,7103,212],{"class":142},[88,7105,369],{"class":368},[88,7107,136],{"class":135},[88,7109,154],{"class":153},[88,7111,376],{"class":157},[88,7113,154],{"class":153},[88,7115,163],{"class":142},[16,7117,7118],{},"Other formats:",[79,7120,7122],{"className":81,"code":7121,"language":83,"meta":84,"style":84},"joined.to_file(\"output\u002Fcustomer_points_with_districts.shp\")\njoined.to_file(\"output\u002Fcustomer_points_with_districts.geojson\", driver=\"GeoJSON\")\n",[52,7123,7124,7143],{"__ignoreMap":84},[88,7125,7126,7128,7130,7132,7134,7136,7139,7141],{"class":90,"line":91},[88,7127,6555],{"class":98},[88,7129,143],{"class":142},[88,7131,354],{"class":146},[88,7133,150],{"class":142},[88,7135,154],{"class":153},[88,7137,7138],{"class":157},"output\u002Fcustomer_points_with_districts.shp",[88,7140,154],{"class":153},[88,7142,163],{"class":142},[88,7144,7145,7147,7149,7151,7153,7155,7158,7160,7162,7164,7166,7168,7170,7172],{"class":90,"line":108},[88,7146,6555],{"class":98},[88,7148,143],{"class":142},[88,7150,354],{"class":146},[88,7152,150],{"class":142},[88,7154,154],{"class":153},[88,7156,7157],{"class":157},"output\u002Fcustomer_points_with_districts.geojson",[88,7159,154],{"class":153},[88,7161,212],{"class":142},[88,7163,369],{"class":368},[88,7165,136],{"class":135},[88,7167,154],{"class":153},[88,7169,1741],{"class":157},[88,7171,154],{"class":153},[88,7173,163],{"class":142},[16,7175,7176],{},"Shapefiles have stricter limits on field names and data types than GeoPackage.",[11,7178,1782],{"id":1781},[397,7180,7182],{"id":7181},"example-1-join-points-to-polygons","Example 1: Join points to polygons",[16,7184,7185],{},"Assign each customer point to a city district.",[79,7187,7189],{"className":81,"code":7188,"language":83,"meta":84,"style":84},"import geopandas as gpd\n\ncustomers = gpd.read_file(\"data\u002Fcustomer_locations.geojson\")\ndistricts = gpd.read_file(\"data\u002Fcity_districts.gpkg\")\n\nif customers.crs != districts.crs:\n    districts = districts.to_crs(customers.crs)\n\nresult = gpd.sjoin(\n    customers,\n    districts[[\"district_name\", \"geometry\"]],\n    how=\"left\",\n    predicate=\"within\"\n)\n\nprint(result[[\"customer_id\", \"district_name\"]].head())\n",[52,7190,7191,7201,7205,7229,7251,7255,7276,7300,7304,7319,7326,7350,7364,7376,7380,7384],{"__ignoreMap":84},[88,7192,7193,7195,7197,7199],{"class":90,"line":91},[88,7194,95],{"class":94},[88,7196,99],{"class":98},[88,7198,102],{"class":94},[88,7200,105],{"class":98},[88,7202,7203],{"class":90,"line":108},[88,7204,126],{"emptyLinePlaceholder":125},[88,7206,7207,7210,7212,7214,7216,7218,7220,7222,7225,7227],{"class":90,"line":122},[88,7208,7209],{"class":98},"customers ",[88,7211,136],{"class":135},[88,7213,139],{"class":98},[88,7215,143],{"class":142},[88,7217,147],{"class":146},[88,7219,150],{"class":142},[88,7221,154],{"class":153},[88,7223,7224],{"class":157},"data\u002Fcustomer_locations.geojson",[88,7226,154],{"class":153},[88,7228,163],{"class":142},[88,7230,7231,7233,7235,7237,7239,7241,7243,7245,7247,7249],{"class":90,"line":129},[88,7232,6619],{"class":98},[88,7234,136],{"class":135},[88,7236,139],{"class":98},[88,7238,143],{"class":142},[88,7240,147],{"class":146},[88,7242,150],{"class":142},[88,7244,154],{"class":153},[88,7246,6436],{"class":157},[88,7248,154],{"class":153},[88,7250,163],{"class":142},[88,7252,7253],{"class":90,"line":166},[88,7254,126],{"emptyLinePlaceholder":125},[88,7256,7257,7259,7262,7264,7266,7268,7270,7272,7274],{"class":90,"line":171},[88,7258,3871],{"class":94},[88,7260,7261],{"class":98}," customers",[88,7263,143],{"class":142},[88,7265,463],{"class":187},[88,7267,6458],{"class":135},[88,7269,6808],{"class":98},[88,7271,143],{"class":142},[88,7273,463],{"class":187},[88,7275,4760],{"class":142},[88,7277,7278,7281,7283,7285,7287,7289,7291,7294,7296,7298],{"class":90,"line":196},[88,7279,7280],{"class":98},"    districts ",[88,7282,136],{"class":135},[88,7284,6808],{"class":98},[88,7286,143],{"class":142},[88,7288,4481],{"class":146},[88,7290,150],{"class":142},[88,7292,7293],{"class":146},"customers",[88,7295,143],{"class":142},[88,7297,463],{"class":187},[88,7299,163],{"class":142},[88,7301,7302],{"class":90,"line":260},[88,7303,126],{"emptyLinePlaceholder":125},[88,7305,7306,7309,7311,7313,7315,7317],{"class":90,"line":265},[88,7307,7308],{"class":98},"result ",[88,7310,136],{"class":135},[88,7312,139],{"class":98},[88,7314,143],{"class":142},[88,7316,6509],{"class":146},[88,7318,4847],{"class":142},[88,7320,7321,7324],{"class":90,"line":290},[88,7322,7323],{"class":146},"    customers",[88,7325,6950],{"class":142},[88,7327,7328,7330,7332,7334,7337,7339,7341,7343,7345,7347],{"class":90,"line":318},[88,7329,6955],{"class":146},[88,7331,679],{"class":142},[88,7333,154],{"class":153},[88,7335,7336],{"class":157},"district_name",[88,7338,154],{"class":153},[88,7340,212],{"class":142},[88,7342,215],{"class":153},[88,7344,188],{"class":157},[88,7346,154],{"class":153},[88,7348,7349],{"class":142},"]],\n",[88,7351,7352,7354,7356,7358,7360,7362],{"class":90,"line":342},[88,7353,6962],{"class":368},[88,7355,136],{"class":135},[88,7357,154],{"class":153},[88,7359,6529],{"class":157},[88,7361,154],{"class":153},[88,7363,6950],{"class":142},[88,7365,7366,7368,7370,7372,7374],{"class":90,"line":347},[88,7367,6977],{"class":368},[88,7369,136],{"class":135},[88,7371,154],{"class":153},[88,7373,6358],{"class":157},[88,7375,2997],{"class":153},[88,7377,7378],{"class":90,"line":3583},[88,7379,163],{"class":142},[88,7381,7382],{"class":90,"line":3601},[88,7383,126],{"emptyLinePlaceholder":125},[88,7385,7386,7388,7390,7393,7395,7397,7400,7402,7404,7406,7408,7410,7412,7414],{"class":90,"line":3620},[88,7387,454],{"class":453},[88,7389,150],{"class":142},[88,7391,7392],{"class":146},"result",[88,7394,679],{"class":142},[88,7396,154],{"class":153},[88,7398,7399],{"class":157},"customer_id",[88,7401,154],{"class":153},[88,7403,212],{"class":142},[88,7405,215],{"class":153},[88,7407,7336],{"class":157},[88,7409,154],{"class":153},[88,7411,696],{"class":142},[88,7413,699],{"class":146},[88,7415,702],{"class":142},[397,7417,7419],{"id":7418},"example-2-keep-all-points-even-when-no-match-is-found","Example 2: Keep all points even when no match is found",[16,7421,7422],{},"Use a left join so unmatched points remain in the output.",[79,7424,7426],{"className":81,"code":7425,"language":83,"meta":84,"style":84},"result = gpd.sjoin(\n    customers,\n    districts[[\"district_name\", \"geometry\"]],\n    how=\"left\",\n    predicate=\"within\"\n)\n\nunmatched = result[result[\"district_name\"].isna()]\nprint(f\"Unmatched points: {len(unmatched)}\")\n",[52,7427,7428,7442,7448,7470,7484,7496,7500,7504,7533],{"__ignoreMap":84},[88,7429,7430,7432,7434,7436,7438,7440],{"class":90,"line":91},[88,7431,7308],{"class":98},[88,7433,136],{"class":135},[88,7435,139],{"class":98},[88,7437,143],{"class":142},[88,7439,6509],{"class":146},[88,7441,4847],{"class":142},[88,7443,7444,7446],{"class":90,"line":108},[88,7445,7323],{"class":146},[88,7447,6950],{"class":142},[88,7449,7450,7452,7454,7456,7458,7460,7462,7464,7466,7468],{"class":90,"line":122},[88,7451,6955],{"class":146},[88,7453,679],{"class":142},[88,7455,154],{"class":153},[88,7457,7336],{"class":157},[88,7459,154],{"class":153},[88,7461,212],{"class":142},[88,7463,215],{"class":153},[88,7465,188],{"class":157},[88,7467,154],{"class":153},[88,7469,7349],{"class":142},[88,7471,7472,7474,7476,7478,7480,7482],{"class":90,"line":129},[88,7473,6962],{"class":368},[88,7475,136],{"class":135},[88,7477,154],{"class":153},[88,7479,6529],{"class":157},[88,7481,154],{"class":153},[88,7483,6950],{"class":142},[88,7485,7486,7488,7490,7492,7494],{"class":90,"line":166},[88,7487,6977],{"class":368},[88,7489,136],{"class":135},[88,7491,154],{"class":153},[88,7493,6358],{"class":157},[88,7495,2997],{"class":153},[88,7497,7498],{"class":90,"line":171},[88,7499,163],{"class":142},[88,7501,7502],{"class":90,"line":196},[88,7503,126],{"emptyLinePlaceholder":125},[88,7505,7506,7509,7511,7514,7516,7518,7520,7522,7524,7526,7528,7531],{"class":90,"line":260},[88,7507,7508],{"class":98},"unmatched ",[88,7510,136],{"class":135},[88,7512,7513],{"class":98}," result",[88,7515,206],{"class":142},[88,7517,7392],{"class":98},[88,7519,206],{"class":142},[88,7521,154],{"class":153},[88,7523,7336],{"class":157},[88,7525,154],{"class":153},[88,7527,247],{"class":142},[88,7529,7530],{"class":146},"isna",[88,7532,287],{"class":142},[88,7534,7535,7537,7539,7541,7544,7546,7548,7550,7553,7555,7557,7559],{"class":90,"line":265},[88,7536,454],{"class":453},[88,7538,150],{"class":142},[88,7540,3898],{"class":3227},[88,7542,7543],{"class":157},"\"Unmatched points: ",[88,7545,3904],{"class":822},[88,7547,493],{"class":453},[88,7549,150],{"class":142},[88,7551,7552],{"class":146},"unmatched",[88,7554,3322],{"class":142},[88,7556,3909],{"class":822},[88,7558,154],{"class":157},[88,7560,163],{"class":142},[16,7562,7563,7564,7567],{},"Unmatched features will have ",[52,7565,7566],{},"NaN"," in the joined columns.",[397,7569,7571],{"id":7570},"example-3-join-overlapping-polygons","Example 3: Join overlapping polygons",[16,7573,7574],{},"Join flood zones to parcel polygons where they intersect.",[79,7576,7578],{"className":81,"code":7577,"language":83,"meta":84,"style":84},"import geopandas as gpd\n\nparcels = gpd.read_file(\"data\u002Fparcels.shp\")\nflood_zones = gpd.read_file(\"data\u002Fflood_zones.shp\")\n\nif parcels.crs != flood_zones.crs:\n    flood_zones = flood_zones.to_crs(parcels.crs)\n\nparcel_flood = gpd.sjoin(\n    parcels,\n    flood_zones[[\"zone_type\", \"geometry\"]],\n    how=\"inner\",\n    predicate=\"intersects\"\n)\n\nprint(parcel_flood[[\"parcel_id\", \"zone_type\"]].head())\n",[52,7579,7580,7590,7594,7616,7640,7644,7665,7688,7692,7707,7714,7738,7752,7764,7768,7772],{"__ignoreMap":84},[88,7581,7582,7584,7586,7588],{"class":90,"line":91},[88,7583,95],{"class":94},[88,7585,99],{"class":98},[88,7587,102],{"class":94},[88,7589,105],{"class":98},[88,7591,7592],{"class":90,"line":108},[88,7593,126],{"emptyLinePlaceholder":125},[88,7595,7596,7598,7600,7602,7604,7606,7608,7610,7612,7614],{"class":90,"line":122},[88,7597,5748],{"class":98},[88,7599,136],{"class":135},[88,7601,139],{"class":98},[88,7603,143],{"class":142},[88,7605,147],{"class":146},[88,7607,150],{"class":142},[88,7609,154],{"class":153},[88,7611,158],{"class":157},[88,7613,154],{"class":153},[88,7615,163],{"class":142},[88,7617,7618,7621,7623,7625,7627,7629,7631,7633,7636,7638],{"class":90,"line":129},[88,7619,7620],{"class":98},"flood_zones ",[88,7622,136],{"class":135},[88,7624,139],{"class":98},[88,7626,143],{"class":142},[88,7628,147],{"class":146},[88,7630,150],{"class":142},[88,7632,154],{"class":153},[88,7634,7635],{"class":157},"data\u002Fflood_zones.shp",[88,7637,154],{"class":153},[88,7639,163],{"class":142},[88,7641,7642],{"class":90,"line":166},[88,7643,126],{"emptyLinePlaceholder":125},[88,7645,7646,7648,7650,7652,7654,7656,7659,7661,7663],{"class":90,"line":171},[88,7647,3871],{"class":94},[88,7649,5841],{"class":98},[88,7651,143],{"class":142},[88,7653,463],{"class":187},[88,7655,6458],{"class":135},[88,7657,7658],{"class":98}," flood_zones",[88,7660,143],{"class":142},[88,7662,463],{"class":187},[88,7664,4760],{"class":142},[88,7666,7667,7670,7672,7674,7676,7678,7680,7682,7684,7686],{"class":90,"line":196},[88,7668,7669],{"class":98},"    flood_zones ",[88,7671,136],{"class":135},[88,7673,7658],{"class":98},[88,7675,143],{"class":142},[88,7677,4481],{"class":146},[88,7679,150],{"class":142},[88,7681,5813],{"class":146},[88,7683,143],{"class":142},[88,7685,463],{"class":187},[88,7687,163],{"class":142},[88,7689,7690],{"class":90,"line":260},[88,7691,126],{"emptyLinePlaceholder":125},[88,7693,7694,7697,7699,7701,7703,7705],{"class":90,"line":265},[88,7695,7696],{"class":98},"parcel_flood ",[88,7698,136],{"class":135},[88,7700,139],{"class":98},[88,7702,143],{"class":142},[88,7704,6509],{"class":146},[88,7706,4847],{"class":142},[88,7708,7709,7712],{"class":90,"line":290},[88,7710,7711],{"class":146},"    parcels",[88,7713,6950],{"class":142},[88,7715,7716,7719,7721,7723,7726,7728,7730,7732,7734,7736],{"class":90,"line":318},[88,7717,7718],{"class":146},"    flood_zones",[88,7720,679],{"class":142},[88,7722,154],{"class":153},[88,7724,7725],{"class":157},"zone_type",[88,7727,154],{"class":153},[88,7729,212],{"class":142},[88,7731,215],{"class":153},[88,7733,188],{"class":157},[88,7735,154],{"class":153},[88,7737,7349],{"class":142},[88,7739,7740,7742,7744,7746,7748,7750],{"class":90,"line":342},[88,7741,6962],{"class":368},[88,7743,136],{"class":135},[88,7745,154],{"class":153},[88,7747,7004],{"class":157},[88,7749,154],{"class":153},[88,7751,6950],{"class":142},[88,7753,7754,7756,7758,7760,7762],{"class":90,"line":347},[88,7755,6977],{"class":368},[88,7757,136],{"class":135},[88,7759,154],{"class":153},[88,7761,6354],{"class":157},[88,7763,2997],{"class":153},[88,7765,7766],{"class":90,"line":3583},[88,7767,163],{"class":142},[88,7769,7770],{"class":90,"line":3601},[88,7771,126],{"emptyLinePlaceholder":125},[88,7773,7774,7776,7778,7781,7783,7785,7788,7790,7792,7794,7796,7798,7800,7802],{"class":90,"line":3620},[88,7775,454],{"class":453},[88,7777,150],{"class":142},[88,7779,7780],{"class":146},"parcel_flood",[88,7782,679],{"class":142},[88,7784,154],{"class":153},[88,7786,7787],{"class":157},"parcel_id",[88,7789,154],{"class":153},[88,7791,212],{"class":142},[88,7793,215],{"class":153},[88,7795,7725],{"class":157},[88,7797,154],{"class":153},[88,7799,696],{"class":142},[88,7801,699],{"class":146},[88,7803,702],{"class":142},[16,7805,7806],{},"One parcel can produce multiple rows if it intersects more than one flood polygon.",[397,7808,7810],{"id":7809},"example-4-reproject-before-joining","Example 4: Reproject before joining",[16,7812,7813],{},"Fix a CRS mismatch before running the join.",[79,7815,7817],{"className":81,"code":7816,"language":83,"meta":84,"style":84},"import geopandas as gpd\n\nsites = gpd.read_file(\"data\u002Fsites.geojson\")\nboundaries = gpd.read_file(\"data\u002Fadmin_boundaries.shp\")\n\nprint(sites.crs)\nprint(boundaries.crs)\n\nif sites.crs != boundaries.crs:\n    boundaries = boundaries.to_crs(sites.crs)\n\njoined = gpd.sjoin(\n    sites,\n    boundaries[[\"admin_name\", \"geometry\"]],\n    how=\"left\",\n    predicate=\"within\"\n)\n\nprint(joined.head())\n",[52,7818,7819,7829,7833,7857,7881,7885,7900,7915,7919,7941,7964,7968,7982,7989,8013,8027,8039,8043,8047],{"__ignoreMap":84},[88,7820,7821,7823,7825,7827],{"class":90,"line":91},[88,7822,95],{"class":94},[88,7824,99],{"class":98},[88,7826,102],{"class":94},[88,7828,105],{"class":98},[88,7830,7831],{"class":90,"line":108},[88,7832,126],{"emptyLinePlaceholder":125},[88,7834,7835,7838,7840,7842,7844,7846,7848,7850,7853,7855],{"class":90,"line":122},[88,7836,7837],{"class":98},"sites ",[88,7839,136],{"class":135},[88,7841,139],{"class":98},[88,7843,143],{"class":142},[88,7845,147],{"class":146},[88,7847,150],{"class":142},[88,7849,154],{"class":153},[88,7851,7852],{"class":157},"data\u002Fsites.geojson",[88,7854,154],{"class":153},[88,7856,163],{"class":142},[88,7858,7859,7862,7864,7866,7868,7870,7872,7874,7877,7879],{"class":90,"line":129},[88,7860,7861],{"class":98},"boundaries ",[88,7863,136],{"class":135},[88,7865,139],{"class":98},[88,7867,143],{"class":142},[88,7869,147],{"class":146},[88,7871,150],{"class":142},[88,7873,154],{"class":153},[88,7875,7876],{"class":157},"data\u002Fadmin_boundaries.shp",[88,7878,154],{"class":153},[88,7880,163],{"class":142},[88,7882,7883],{"class":90,"line":166},[88,7884,126],{"emptyLinePlaceholder":125},[88,7886,7887,7889,7891,7894,7896,7898],{"class":90,"line":171},[88,7888,454],{"class":453},[88,7890,150],{"class":142},[88,7892,7893],{"class":146},"sites",[88,7895,143],{"class":142},[88,7897,463],{"class":187},[88,7899,163],{"class":142},[88,7901,7902,7904,7906,7909,7911,7913],{"class":90,"line":196},[88,7903,454],{"class":453},[88,7905,150],{"class":142},[88,7907,7908],{"class":146},"boundaries",[88,7910,143],{"class":142},[88,7912,463],{"class":187},[88,7914,163],{"class":142},[88,7916,7917],{"class":90,"line":260},[88,7918,126],{"emptyLinePlaceholder":125},[88,7920,7921,7923,7926,7928,7930,7932,7935,7937,7939],{"class":90,"line":265},[88,7922,3871],{"class":94},[88,7924,7925],{"class":98}," sites",[88,7927,143],{"class":142},[88,7929,463],{"class":187},[88,7931,6458],{"class":135},[88,7933,7934],{"class":98}," boundaries",[88,7936,143],{"class":142},[88,7938,463],{"class":187},[88,7940,4760],{"class":142},[88,7942,7943,7946,7948,7950,7952,7954,7956,7958,7960,7962],{"class":90,"line":290},[88,7944,7945],{"class":98},"    boundaries ",[88,7947,136],{"class":135},[88,7949,7934],{"class":98},[88,7951,143],{"class":142},[88,7953,4481],{"class":146},[88,7955,150],{"class":142},[88,7957,7893],{"class":146},[88,7959,143],{"class":142},[88,7961,463],{"class":187},[88,7963,163],{"class":142},[88,7965,7966],{"class":90,"line":318},[88,7967,126],{"emptyLinePlaceholder":125},[88,7969,7970,7972,7974,7976,7978,7980],{"class":90,"line":342},[88,7971,6500],{"class":98},[88,7973,136],{"class":135},[88,7975,139],{"class":98},[88,7977,143],{"class":142},[88,7979,6509],{"class":146},[88,7981,4847],{"class":142},[88,7983,7984,7987],{"class":90,"line":347},[88,7985,7986],{"class":146},"    sites",[88,7988,6950],{"class":142},[88,7990,7991,7994,7996,7998,8001,8003,8005,8007,8009,8011],{"class":90,"line":3583},[88,7992,7993],{"class":146},"    boundaries",[88,7995,679],{"class":142},[88,7997,154],{"class":153},[88,7999,8000],{"class":157},"admin_name",[88,8002,154],{"class":153},[88,8004,212],{"class":142},[88,8006,215],{"class":153},[88,8008,188],{"class":157},[88,8010,154],{"class":153},[88,8012,7349],{"class":142},[88,8014,8015,8017,8019,8021,8023,8025],{"class":90,"line":3601},[88,8016,6962],{"class":368},[88,8018,136],{"class":135},[88,8020,154],{"class":153},[88,8022,6529],{"class":157},[88,8024,154],{"class":153},[88,8026,6950],{"class":142},[88,8028,8029,8031,8033,8035,8037],{"class":90,"line":3620},[88,8030,6977],{"class":368},[88,8032,136],{"class":135},[88,8034,154],{"class":153},[88,8036,6358],{"class":157},[88,8038,2997],{"class":153},[88,8040,8041],{"class":90,"line":3625},[88,8042,163],{"class":142},[88,8044,8045],{"class":90,"line":3643},[88,8046,126],{"emptyLinePlaceholder":125},[88,8048,8049,8051,8053,8055,8057,8059],{"class":90,"line":3658},[88,8050,454],{"class":453},[88,8052,150],{"class":142},[88,8054,6555],{"class":146},[88,8056,143],{"class":142},[88,8058,699],{"class":146},[88,8060,702],{"class":142},[11,8062,2483],{"id":2482},[16,8064,8065],{},"A spatial join is different from a normal attribute join.",[23,8067,8068,8073],{},[26,8069,8070,8071],{},"An attribute join uses a shared key such as ",[52,8072,7787],{},[26,8074,8075],{},"A spatial join uses geometry relationships such as overlap, containment, or intersection",[16,8077,8078,8079,8082],{},"In GeoPandas, ",[52,8080,8081],{},"sjoin()"," compares the geometry in the left GeoDataFrame with the geometry in the right GeoDataFrame using the predicate you choose.",[16,8084,8085],{},"Examples include:",[23,8087,8088,8091,8094],{},[26,8089,8090],{},"point within polygon",[26,8092,8093],{},"polygon intersects polygon",[26,8095,8096],{},"line intersects polygon",[16,8098,8099],{},"GeoPandas uses spatial indexing when available, which reduces the number of geometry comparisons and helps performance on larger datasets.",[16,8101,8102],{},"A spatial join can also increase row counts. One feature may match multiple features, especially when:",[23,8104,8105,8108,8111,8114],{},[26,8106,8107],{},"polygons overlap",[26,8109,8110],{},"a line crosses several polygons",[26,8112,8113],{},"boundary features match more than one geometry",[26,8115,8116],{},"source administrative boundaries or zone layers are not cleanly non-overlapping",[16,8118,8119],{},"That is why the output may contain more rows than the left input layer.",[11,8121,4049],{"id":4048},[397,8123,8125],{"id":8124},"duplicate-matches","Duplicate matches",[16,8127,8128],{},"One feature can match more than one feature.",[16,8130,8131],{},"This often happens with:",[23,8133,8134,8137,8140,8143],{},[26,8135,8136],{},"overlapping polygon layers",[26,8138,8139],{},"polygon-to-polygon joins",[26,8141,8142],{},"line-to-polygon joins",[26,8144,8145],{},"boundary cases depending on the predicate",[16,8147,8148],{},"If you need exactly one match per feature, you will need additional cleanup logic after the join.",[397,8150,8152],{"id":8151},"crs-mismatches","CRS mismatches",[16,8154,8155],{},"Always check CRS before every spatial join.",[79,8157,8159],{"className":81,"code":8158,"language":83,"meta":84,"style":84},"print(left_gdf.crs)\nprint(right_gdf.crs)\n",[52,8160,8161,8176],{"__ignoreMap":84},[88,8162,8163,8165,8167,8170,8172,8174],{"class":90,"line":91},[88,8164,454],{"class":453},[88,8166,150],{"class":142},[88,8168,8169],{"class":146},"left_gdf",[88,8171,143],{"class":142},[88,8173,463],{"class":187},[88,8175,163],{"class":142},[88,8177,8178,8180,8182,8185,8187,8189],{"class":90,"line":108},[88,8179,454],{"class":453},[88,8181,150],{"class":142},[88,8183,8184],{"class":146},"right_gdf",[88,8186,143],{"class":142},[88,8188,463],{"class":187},[88,8190,163],{"class":142},[16,8192,8193],{},"If needed:",[79,8195,8197],{"className":81,"code":8196,"language":83,"meta":84,"style":84},"right_gdf = right_gdf.to_crs(left_gdf.crs)\n",[52,8198,8199],{"__ignoreMap":84},[88,8200,8201,8204,8206,8209,8211,8213,8215,8217,8219,8221],{"class":90,"line":91},[88,8202,8203],{"class":98},"right_gdf ",[88,8205,136],{"class":135},[88,8207,8208],{"class":98}," right_gdf",[88,8210,143],{"class":142},[88,8212,4481],{"class":146},[88,8214,150],{"class":142},[88,8216,8169],{"class":146},[88,8218,143],{"class":142},[88,8220,463],{"class":187},[88,8222,163],{"class":142},[397,8224,8226],{"id":8225},"missing-or-invalid-geometries","Missing or invalid geometries",[16,8228,8229],{},"Null or invalid geometries can cause missing matches or errors.",[79,8231,8233],{"className":81,"code":8232,"language":83,"meta":84,"style":84},"left_gdf = left_gdf[left_gdf.geometry.notna()]\nright_gdf = right_gdf[right_gdf.geometry.notna()]\n\nright_gdf = right_gdf[right_gdf.is_valid]\n",[52,8234,8235,8259,8281,8285],{"__ignoreMap":84},[88,8236,8237,8240,8242,8245,8247,8249,8251,8253,8255,8257],{"class":90,"line":91},[88,8238,8239],{"class":98},"left_gdf ",[88,8241,136],{"class":135},[88,8243,8244],{"class":98}," left_gdf",[88,8246,206],{"class":142},[88,8248,8169],{"class":98},[88,8250,143],{"class":142},[88,8252,188],{"class":187},[88,8254,143],{"class":142},[88,8256,284],{"class":146},[88,8258,287],{"class":142},[88,8260,8261,8263,8265,8267,8269,8271,8273,8275,8277,8279],{"class":90,"line":108},[88,8262,8203],{"class":98},[88,8264,136],{"class":135},[88,8266,8208],{"class":98},[88,8268,206],{"class":142},[88,8270,8184],{"class":98},[88,8272,143],{"class":142},[88,8274,188],{"class":187},[88,8276,143],{"class":142},[88,8278,284],{"class":146},[88,8280,287],{"class":142},[88,8282,8283],{"class":90,"line":122},[88,8284,126],{"emptyLinePlaceholder":125},[88,8286,8287,8289,8291,8293,8295,8297,8299,8301],{"class":90,"line":129},[88,8288,8203],{"class":98},[88,8290,136],{"class":135},[88,8292,8208],{"class":98},[88,8294,206],{"class":142},[88,8296,8184],{"class":98},[88,8298,143],{"class":142},[88,8300,337],{"class":187},[88,8302,315],{"class":142},[16,8304,8305],{},"In some workflows, you may need to repair invalid geometry before joining.",[397,8307,8309],{"id":8308},"boundary-behavior","Boundary behavior",[16,8311,8312],{},"Points or lines on polygon boundaries can produce unexpected results.",[23,8314,8315,8320,8325],{},[26,8316,8317,8319],{},[52,8318,6358],{}," requires the left geometry to be in the interior of the right geometry",[26,8321,8322,8324],{},[52,8323,6362],{}," is also strict and does not treat boundary-only contact as contained",[26,8326,8327,8329],{},[52,8328,6354],{}," is more inclusive and matches touching geometries",[16,8331,8332,8333,8335],{},"If features on edges are not matching as expected, test ",[52,8334,6354],{}," and compare the output.",[397,8337,8339],{"id":8338},"performance-on-large-datasets","Performance on large datasets",[16,8341,8342],{},"Large joins can be slow.",[16,8344,8345],{},"To reduce overhead:",[23,8347,8348,8351,8354,8357],{},[26,8349,8350],{},"keep only the columns you need before joining",[26,8352,8353],{},"make sure a spatial index is available",[26,8355,8356],{},"filter either dataset first if you can reduce the search area",[26,8358,8359],{},"avoid unnecessary reprojection or repeated file reads inside loops",[11,8361,2612],{"id":2611},[16,8363,8364,8365,143],{},"If you need the underlying concept first, read ",[2617,8366,8367],{"href":4208},"What Is a Spatial Join in GIS?",[16,8369,8370],{},"Related tasks:",[23,8372,8373,8377],{},[26,8374,8375],{},[2617,8376,4205],{"href":4204},[26,8378,8379],{},[2617,8380,2631],{"href":2630},[16,8382,8383,8384,143],{},"If your join returns empty or unexpected output, see ",[2617,8385,8386],{"href":4208},"Why Is My GeoPandas Spatial Join Returning No Results?",[11,8388,2647],{"id":2646},[397,8390,8392],{"id":8391},"how-do-i-do-a-spatial-join-in-geopandas","How do I do a spatial join in GeoPandas?",[16,8394,383,8395,8398],{},[52,8396,8397],{},"gpd.sjoin(left_gdf, right_gdf, how=..., predicate=...)",". Both inputs must be GeoDataFrames and both must use the same CRS.",[79,8400,8402],{"className":81,"code":8401,"language":83,"meta":84,"style":84},"joined = gpd.sjoin(points, polygons, how=\"left\", predicate=\"within\")\n",[52,8403,8404],{"__ignoreMap":84},[88,8405,8406,8408,8410,8412,8414,8416,8418,8420,8422,8424,8426,8428,8430,8432,8434,8436,8438,8440,8442,8444,8446,8448],{"class":90,"line":91},[88,8407,6500],{"class":98},[88,8409,136],{"class":135},[88,8411,139],{"class":98},[88,8413,143],{"class":142},[88,8415,6509],{"class":146},[88,8417,150],{"class":142},[88,8419,6485],{"class":146},[88,8421,212],{"class":142},[88,8423,6461],{"class":146},[88,8425,212],{"class":142},[88,8427,6522],{"class":368},[88,8429,136],{"class":135},[88,8431,154],{"class":153},[88,8433,6529],{"class":157},[88,8435,154],{"class":153},[88,8437,212],{"class":142},[88,8439,6536],{"class":368},[88,8441,136],{"class":135},[88,8443,154],{"class":153},[88,8445,6358],{"class":157},[88,8447,154],{"class":153},[88,8449,163],{"class":142},[397,8451,6215,8453,6355,8455,8457,8458,8460],{"id":8452},"what-is-the-difference-between-intersects-within-and-contains-in-a-spatial-join",[52,8454,6354],{},[52,8456,6358],{},", and ",[52,8459,6362],{}," in a spatial join?",[23,8462,8463,8468,8473],{},[26,8464,8465,8467],{},[52,8466,6354],{},": geometries touch or overlap in any way",[26,8469,8470,8472],{},[52,8471,6358],{},": left geometry is inside the right geometry",[26,8474,8475,8477],{},[52,8476,6362],{},": left geometry contains the right geometry",[16,8479,8480,8481,8483],{},"For joining points to polygons, ",[52,8482,6358],{}," is usually the best starting point.",[397,8485,8487],{"id":8486},"why-does-my-spatial-join-return-empty-results","Why does my spatial join return empty results?",[16,8489,8490],{},"Common causes include:",[23,8492,8493,8496,8499,8502],{},[26,8494,8495],{},"CRS mismatch",[26,8497,8498],{},"wrong predicate",[26,8500,8501],{},"invalid or null geometries",[26,8503,8504],{},"empty input layers",[16,8506,8507],{},"Check CRS first, then inspect geometry validity and test a different predicate.",[397,8509,8511],{"id":8510},"why-do-i-get-multiple-rows-for-one-feature-after-a-spatial-join","Why do I get multiple rows for one feature after a spatial join?",[16,8513,8514],{},"Because one feature can match multiple features in the other layer. This is common with overlapping polygons and polygon intersection joins.",[2693,8516,8517],{},"html pre.shiki code .sVHd0, html code.shiki .sVHd0{--shiki-light:#39ADB5;--shiki-light-font-style:italic;--shiki-default:#D73A49;--shiki-default-font-style:inherit;--shiki-dark:#F97583;--shiki-dark-font-style:inherit}html pre.shiki code .su5hD, html code.shiki .su5hD{--shiki-light:#90A4AE;--shiki-default:#24292E;--shiki-dark:#E1E4E8}html pre.shiki code .smGrS, html code.shiki .smGrS{--shiki-light:#39ADB5;--shiki-default:#D73A49;--shiki-dark:#F97583}html pre.shiki code .sP7_E, html code.shiki .sP7_E{--shiki-light:#39ADB5;--shiki-default:#24292E;--shiki-dark:#E1E4E8}html pre.shiki code .slqww, html code.shiki .slqww{--shiki-light:#6182B8;--shiki-default:#24292E;--shiki-dark:#E1E4E8}html pre.shiki code .sjJ54, html code.shiki .sjJ54{--shiki-light:#39ADB5;--shiki-default:#032F62;--shiki-dark:#9ECBFF}html pre.shiki code .s_sjI, html code.shiki .s_sjI{--shiki-light:#91B859;--shiki-default:#032F62;--shiki-dark:#9ECBFF}html pre.shiki code .skxfh, html code.shiki .skxfh{--shiki-light:#E53935;--shiki-default:#24292E;--shiki-dark:#E1E4E8}html pre.shiki code .s99_P, html code.shiki .s99_P{--shiki-light:#90A4AE;--shiki-light-font-style:italic;--shiki-default:#E36209;--shiki-default-font-style:inherit;--shiki-dark:#FFAB70;--shiki-dark-font-style:inherit}html pre.shiki code .sptTA, html code.shiki .sptTA{--shiki-light:#6182B8;--shiki-default:#005CC5;--shiki-dark:#79B8FF}html .light .shiki span {color: var(--shiki-light);background: var(--shiki-light-bg);font-style: var(--shiki-light-font-style);font-weight: var(--shiki-light-font-weight);text-decoration: var(--shiki-light-text-decoration);}html.light .shiki span {color: var(--shiki-light);background: var(--shiki-light-bg);font-style: var(--shiki-light-font-style);font-weight: var(--shiki-light-font-weight);text-decoration: var(--shiki-light-text-decoration);}html .default .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html.dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html pre.shiki code .sZMiF, html code.shiki .sZMiF{--shiki-light:#E2931D;--shiki-default:#005CC5;--shiki-dark:#79B8FF}html pre.shiki code .sbsja, html code.shiki .sbsja{--shiki-light:#9C3EDA;--shiki-default:#D73A49;--shiki-dark:#F97583}html pre.shiki code .srdBf, html code.shiki .srdBf{--shiki-light:#F76D47;--shiki-default:#005CC5;--shiki-dark:#79B8FF}",{"title":84,"searchDepth":108,"depth":108,"links":8519},[8520,8521,8522,8531,8537,8538,8545,8546],{"id":13,"depth":108,"text":14},{"id":73,"depth":108,"text":74},{"id":394,"depth":108,"text":395,"children":8523},[8524,8525,8526,8527,8528,8529,8530],{"id":6569,"depth":122,"text":6570},{"id":6686,"depth":122,"text":6687},{"id":6754,"depth":122,"text":6755},{"id":6828,"depth":122,"text":6829},{"id":6916,"depth":122,"text":6917},{"id":7017,"depth":122,"text":7018},{"id":7075,"depth":122,"text":7076},{"id":1781,"depth":108,"text":1782,"children":8532},[8533,8534,8535,8536],{"id":7181,"depth":122,"text":7182},{"id":7418,"depth":122,"text":7419},{"id":7570,"depth":122,"text":7571},{"id":7809,"depth":122,"text":7810},{"id":2482,"depth":108,"text":2483},{"id":4048,"depth":108,"text":4049,"children":8539},[8540,8541,8542,8543,8544],{"id":8124,"depth":122,"text":8125},{"id":8151,"depth":122,"text":8152},{"id":8225,"depth":122,"text":8226},{"id":8308,"depth":122,"text":8309},{"id":8338,"depth":122,"text":8339},{"id":2611,"depth":108,"text":2612},{"id":2646,"depth":108,"text":2647,"children":8547},[8548,8549,8551,8552],{"id":8391,"depth":122,"text":8392},{"id":8452,"depth":122,"text":8550},"What is the difference between intersects, within, and contains in a spatial join?",{"id":8486,"depth":122,"text":8487},{"id":8510,"depth":122,"text":8511},"How to perform a spatial join in Python with GeoPandas sjoin(), with examples for point-in-polygon and other predicates.",{},"\u002Ftasks\u002Fspatial-join-python-geopandas",{"title":4209,"description":8553},"tasks\u002Fspatial-join-python-geopandas","a-HG9WHGVnUi8hUaDr7OH_ohBtTXUAY8t9YmRtjhIPw",{"id":8560,"title":2637,"body":8561,"description":10259,"extension":2741,"meta":10260,"navigation":125,"path":10261,"seo":10262,"stem":10263,"__hash__":10264},"content\u002Ftasks\u002Fwrite-geojson-python.md",{"type":8,"value":8562,"toc":10227},[8563,8565,8568,8574,8588,8595,8598,8612,8615,8617,8626,8723,8726,8743,8749,8751,8755,8758,8831,8834,8847,8850,8854,8857,8936,8939,8952,8955,8959,8965,9012,9015,9023,9026,9030,9038,9084,9089,9092,9096,9099,9170,9173,9187,9189,9193,9196,9269,9273,9276,9347,9350,9354,9357,9485,9488,9492,9495,9661,9664,9666,9674,9680,9690,9693,9696,9699,9702,9704,9708,9711,9839,9843,9850,9868,9871,9899,9901,9904,9956,9959,9992,9995,9999,10002,10006,10009,10020,10023,10025,10030,10032,10042,10048,10050,10054,10059,10095,10098,10102,10108,10135,10139,10142,10201,10205,10207,10221,10224],[11,8564,14],{"id":13},[16,8566,8567],{},"A common GIS task is exporting spatial data from Python into GeoJSON so it can be used in web maps, APIs, QGIS, or other downstream workflows.",[16,8569,8570,8571,8573],{},"In many cases, the data is already in a GeoPandas ",[52,8572,2781],{},". You may have:",[23,8575,8576,8579,8582,8585],{},[26,8577,8578],{},"read a shapefile into Python",[26,8580,8581],{},"loaded a GeoPackage layer",[26,8583,8584],{},"filtered an existing GeoDataFrame",[26,8586,8587],{},"created new geometries in code",[16,8589,8590,8591,8594],{},"The main question is usually: what is the correct way to write that GeoDataFrame to a ",[52,8592,8593],{},".geojson"," file?",[16,8596,8597],{},"The practical issues are:",[23,8599,8600,8603,8606,8609],{},[26,8601,8602],{},"using the right GeoPandas export method",[26,8604,8605],{},"choosing the correct driver",[26,8607,8608],{},"making sure the CRS is appropriate",[26,8610,8611],{},"avoiding problems with invalid geometries or messy attribute fields",[16,8613,8614],{},"If your goal is to export GeoJSON in Python with GeoPandas, the standard workflow is straightforward once those checks are in place.",[11,8616,74],{"id":73},[16,8618,383,8619,8622,8623,8625],{},[52,8620,8621],{},"GeoDataFrame.to_file()"," with the ",[52,8624,1741],{}," driver:",[79,8627,8629],{"className":81,"code":8628,"language":83,"meta":84,"style":84},"import geopandas as gpd\n\ngdf = gpd.read_file(\"data\u002Froads.shp\")\ngdf = gdf.to_crs(\"EPSG:4326\")  # recommended for GeoJSON compatibility\ngdf.to_file(\"output\u002Froads.geojson\", driver=\"GeoJSON\")\n",[52,8630,8631,8641,8645,8667,8692],{"__ignoreMap":84},[88,8632,8633,8635,8637,8639],{"class":90,"line":91},[88,8634,95],{"class":94},[88,8636,99],{"class":98},[88,8638,102],{"class":94},[88,8640,105],{"class":98},[88,8642,8643],{"class":90,"line":108},[88,8644,126],{"emptyLinePlaceholder":125},[88,8646,8647,8649,8651,8653,8655,8657,8659,8661,8663,8665],{"class":90,"line":122},[88,8648,132],{"class":98},[88,8650,136],{"class":135},[88,8652,139],{"class":98},[88,8654,143],{"class":142},[88,8656,147],{"class":146},[88,8658,150],{"class":142},[88,8660,154],{"class":153},[88,8662,2831],{"class":157},[88,8664,154],{"class":153},[88,8666,163],{"class":142},[88,8668,8669,8671,8673,8675,8677,8679,8681,8683,8685,8687,8689],{"class":90,"line":129},[88,8670,132],{"class":98},[88,8672,136],{"class":135},[88,8674,228],{"class":98},[88,8676,143],{"class":142},[88,8678,4481],{"class":146},[88,8680,150],{"class":142},[88,8682,154],{"class":153},[88,8684,4125],{"class":157},[88,8686,154],{"class":153},[88,8688,3322],{"class":142},[88,8690,8691],{"class":5275},"  # recommended for GeoJSON compatibility\n",[88,8693,8694,8696,8698,8700,8702,8704,8707,8709,8711,8713,8715,8717,8719,8721],{"class":90,"line":166},[88,8695,182],{"class":98},[88,8697,143],{"class":142},[88,8699,354],{"class":146},[88,8701,150],{"class":142},[88,8703,154],{"class":153},[88,8705,8706],{"class":157},"output\u002Froads.geojson",[88,8708,154],{"class":153},[88,8710,212],{"class":142},[88,8712,369],{"class":368},[88,8714,136],{"class":135},[88,8716,154],{"class":153},[88,8718,1741],{"class":157},[88,8720,154],{"class":153},[88,8722,163],{"class":142},[16,8724,8725],{},"Before exporting, check:",[23,8727,8728,8734,8737,8740],{},[26,8729,8730,8731,8733],{},"that ",[52,8732,182],{}," is a valid GeoDataFrame",[26,8735,8736],{},"that it has a geometry column",[26,8738,8739],{},"that the CRS is correct",[26,8741,8742],{},"that the output path is valid",[16,8744,8745,8746,8748],{},"For GeoJSON interoperability, exporting in WGS84 longitude\u002Flatitude (",[52,8747,4125],{},") is the safest choice.",[11,8750,395],{"id":394},[397,8752,8754],{"id":8753},"load-or-prepare-the-geodataframe","Load or prepare the GeoDataFrame",[16,8756,8757],{},"Start with an existing GeoDataFrame or read spatial data from disk.",[79,8759,8761],{"className":81,"code":8760,"language":83,"meta":84,"style":84},"import geopandas as gpd\n\ngdf = gpd.read_file(\"data\u002Fparcels.shp\")\nprint(type(gdf))\nprint(gdf.geometry.name)\n",[52,8762,8763,8773,8777,8799,8813],{"__ignoreMap":84},[88,8764,8765,8767,8769,8771],{"class":90,"line":91},[88,8766,95],{"class":94},[88,8768,99],{"class":98},[88,8770,102],{"class":94},[88,8772,105],{"class":98},[88,8774,8775],{"class":90,"line":108},[88,8776,126],{"emptyLinePlaceholder":125},[88,8778,8779,8781,8783,8785,8787,8789,8791,8793,8795,8797],{"class":90,"line":122},[88,8780,132],{"class":98},[88,8782,136],{"class":135},[88,8784,139],{"class":98},[88,8786,143],{"class":142},[88,8788,147],{"class":146},[88,8790,150],{"class":142},[88,8792,154],{"class":153},[88,8794,158],{"class":157},[88,8796,154],{"class":153},[88,8798,163],{"class":142},[88,8800,8801,8803,8805,8807,8809,8811],{"class":90,"line":129},[88,8802,454],{"class":453},[88,8804,150],{"class":142},[88,8806,6651],{"class":3892},[88,8808,150],{"class":142},[88,8810,182],{"class":146},[88,8812,500],{"class":142},[88,8814,8815,8817,8819,8821,8823,8825,8827,8829],{"class":90,"line":166},[88,8816,454],{"class":453},[88,8818,150],{"class":142},[88,8820,182],{"class":146},[88,8822,143],{"class":142},[88,8824,188],{"class":187},[88,8826,143],{"class":142},[88,8828,482],{"class":187},[88,8830,163],{"class":142},[16,8832,8833],{},"You should confirm that:",[23,8835,8836,8841,8844],{},[26,8837,8838,8839],{},"the object is a ",[52,8840,2781],{},[26,8842,8843],{},"the geometry column exists",[26,8845,8846],{},"the data loaded correctly",[16,8848,8849],{},"If you already have a GeoDataFrame from previous processing, you can export it directly.",[397,8851,8853],{"id":8852},"inspect-the-data-before-export","Inspect the data before export",[16,8855,8856],{},"Before writing the file, inspect the structure of the dataset.",[79,8858,8860],{"className":81,"code":8859,"language":83,"meta":84,"style":84},"print(gdf.head())\nprint(gdf.columns)\nprint(len(gdf))\nprint(gdf.geom_type.unique())\nprint(gdf.crs)\n",[52,8861,8862,8876,8890,8904,8922],{"__ignoreMap":84},[88,8863,8864,8866,8868,8870,8872,8874],{"class":90,"line":91},[88,8865,454],{"class":453},[88,8867,150],{"class":142},[88,8869,182],{"class":146},[88,8871,143],{"class":142},[88,8873,699],{"class":146},[88,8875,702],{"class":142},[88,8877,8878,8880,8882,8884,8886,8888],{"class":90,"line":108},[88,8879,454],{"class":453},[88,8881,150],{"class":142},[88,8883,182],{"class":146},[88,8885,143],{"class":142},[88,8887,3096],{"class":187},[88,8889,163],{"class":142},[88,8891,8892,8894,8896,8898,8900,8902],{"class":90,"line":122},[88,8893,454],{"class":453},[88,8895,150],{"class":142},[88,8897,493],{"class":453},[88,8899,150],{"class":142},[88,8901,182],{"class":146},[88,8903,500],{"class":142},[88,8905,8906,8908,8910,8912,8914,8916,8918,8920],{"class":90,"line":129},[88,8907,454],{"class":453},[88,8909,150],{"class":142},[88,8911,182],{"class":146},[88,8913,143],{"class":142},[88,8915,1091],{"class":187},[88,8917,143],{"class":142},[88,8919,3129],{"class":146},[88,8921,702],{"class":142},[88,8923,8924,8926,8928,8930,8932,8934],{"class":90,"line":166},[88,8925,454],{"class":453},[88,8927,150],{"class":142},[88,8929,182],{"class":146},[88,8931,143],{"class":142},[88,8933,463],{"class":187},[88,8935,163],{"class":142},[16,8937,8938],{},"This helps catch common problems early:",[23,8940,8941,8944,8947,8949],{},[26,8942,8943],{},"unexpected columns",[26,8945,8946],{},"mixed geometry types",[26,8948,4611],{},[26,8950,8951],{},"empty datasets",[16,8953,8954],{},"If the output will be used in web tools or APIs, also confirm whether the coordinates are already longitude\u002Flatitude.",[397,8956,8958],{"id":8957},"reproject-to-the-correct-crs-if-needed","Reproject to the correct CRS if needed",[16,8960,8961,8962,8964],{},"For best compatibility, GeoJSON should generally be exported in WGS84 longitude\u002Flatitude coordinates (",[52,8963,4125],{},"). Many web tools expect this, and using another CRS can cause display or interoperability problems.",[79,8966,8968],{"className":81,"code":8967,"language":83,"meta":84,"style":84},"if gdf.crs != \"EPSG:4326\":\n    gdf = gdf.to_crs(\"EPSG:4326\")\n",[52,8969,8970,8990],{"__ignoreMap":84},[88,8971,8972,8974,8976,8978,8980,8982,8984,8986,8988],{"class":90,"line":91},[88,8973,3871],{"class":94},[88,8975,228],{"class":98},[88,8977,143],{"class":142},[88,8979,463],{"class":187},[88,8981,6458],{"class":135},[88,8983,215],{"class":153},[88,8985,4125],{"class":157},[88,8987,154],{"class":153},[88,8989,4760],{"class":142},[88,8991,8992,8994,8996,8998,9000,9002,9004,9006,9008,9010],{"class":90,"line":108},[88,8993,4765],{"class":98},[88,8995,136],{"class":135},[88,8997,228],{"class":98},[88,8999,143],{"class":142},[88,9001,4481],{"class":146},[88,9003,150],{"class":142},[88,9005,154],{"class":153},[88,9007,4125],{"class":157},[88,9009,154],{"class":153},[88,9011,163],{"class":142},[16,9013,9014],{},"Use this when:",[23,9016,9017,9020],{},[26,9018,9019],{},"the output will be used in Leaflet, Mapbox, OpenLayers, or web APIs",[26,9021,9022],{},"the source data is projected, such as UTM or a local state plane CRS",[16,9024,9025],{},"If you keep the source CRS, confirm that the target tool supports it correctly before exporting GeoJSON.",[397,9027,9029],{"id":9028},"export-the-geodataframe-to-geojson","Export the GeoDataFrame to GeoJSON",[16,9031,383,9032,9035,9036,143],{},[52,9033,9034],{},"to_file()"," and set the driver to ",[52,9037,1741],{},[79,9039,9041],{"className":81,"code":9040,"language":83,"meta":84,"style":84},"output_file = \"output\u002Fparcels.geojson\"\ngdf.to_file(output_file, driver=\"GeoJSON\")\n",[52,9042,9043,9057],{"__ignoreMap":84},[88,9044,9045,9048,9050,9052,9055],{"class":90,"line":91},[88,9046,9047],{"class":98},"output_file ",[88,9049,136],{"class":135},[88,9051,215],{"class":153},[88,9053,9054],{"class":157},"output\u002Fparcels.geojson",[88,9056,2997],{"class":153},[88,9058,9059,9061,9063,9065,9067,9070,9072,9074,9076,9078,9080,9082],{"class":90,"line":108},[88,9060,182],{"class":98},[88,9062,143],{"class":142},[88,9064,354],{"class":146},[88,9066,150],{"class":142},[88,9068,9069],{"class":146},"output_file",[88,9071,212],{"class":142},[88,9073,369],{"class":368},[88,9075,136],{"class":135},[88,9077,154],{"class":153},[88,9079,1741],{"class":157},[88,9081,154],{"class":153},[88,9083,163],{"class":142},[16,9085,9086,9087,143],{},"That is the standard GeoPandas method for writing GeoJSON from a ",[52,9088,2781],{},[16,9090,9091],{},"Choose a clear filename and make sure the output folder exists. If you want predictable overwrite behavior, delete or version the output file explicitly before writing.",[397,9093,9095],{"id":9094},"verify-the-exported-geojson-file","Verify the exported GeoJSON file",[16,9097,9098],{},"After export, read the file back in or open it in QGIS.",[79,9100,9102],{"className":81,"code":9101,"language":83,"meta":84,"style":84},"check_gdf = gpd.read_file(\"output\u002Fparcels.geojson\")\nprint(len(check_gdf))\nprint(check_gdf.columns)\nprint(check_gdf.crs)\n",[52,9103,9104,9127,9142,9156],{"__ignoreMap":84},[88,9105,9106,9109,9111,9113,9115,9117,9119,9121,9123,9125],{"class":90,"line":91},[88,9107,9108],{"class":98},"check_gdf ",[88,9110,136],{"class":135},[88,9112,139],{"class":98},[88,9114,143],{"class":142},[88,9116,147],{"class":146},[88,9118,150],{"class":142},[88,9120,154],{"class":153},[88,9122,9054],{"class":157},[88,9124,154],{"class":153},[88,9126,163],{"class":142},[88,9128,9129,9131,9133,9135,9137,9140],{"class":90,"line":108},[88,9130,454],{"class":453},[88,9132,150],{"class":142},[88,9134,493],{"class":453},[88,9136,150],{"class":142},[88,9138,9139],{"class":146},"check_gdf",[88,9141,500],{"class":142},[88,9143,9144,9146,9148,9150,9152,9154],{"class":90,"line":122},[88,9145,454],{"class":453},[88,9147,150],{"class":142},[88,9149,9139],{"class":146},[88,9151,143],{"class":142},[88,9153,3096],{"class":187},[88,9155,163],{"class":142},[88,9157,9158,9160,9162,9164,9166,9168],{"class":90,"line":129},[88,9159,454],{"class":453},[88,9161,150],{"class":142},[88,9163,9139],{"class":146},[88,9165,143],{"class":142},[88,9167,463],{"class":187},[88,9169,163],{"class":142},[16,9171,9172],{},"You should confirm:",[23,9174,9175,9178,9181,9184],{},[26,9176,9177],{},"the feature count matches the original",[26,9179,9180],{},"expected attribute fields are present",[26,9182,9183],{},"geometries display correctly",[26,9185,9186],{},"the CRS is what you intended",[11,9188,1782],{"id":1781},[397,9190,9192],{"id":9191},"example-1-export-a-geodataframe-to-geojson","Example 1: Export a GeoDataFrame to GeoJSON",[16,9194,9195],{},"This is the minimal workflow to export a GeoDataFrame to GeoJSON.",[79,9197,9199],{"className":81,"code":9198,"language":83,"meta":84,"style":84},"import geopandas as gpd\n\ngdf = gpd.read_file(\"data\u002Fbuildings.gpkg\")\ngdf.to_file(\"output\u002Fbuildings.geojson\", driver=\"GeoJSON\")\n",[52,9200,9201,9211,9215,9238],{"__ignoreMap":84},[88,9202,9203,9205,9207,9209],{"class":90,"line":91},[88,9204,95],{"class":94},[88,9206,99],{"class":98},[88,9208,102],{"class":94},[88,9210,105],{"class":98},[88,9212,9213],{"class":90,"line":108},[88,9214,126],{"emptyLinePlaceholder":125},[88,9216,9217,9219,9221,9223,9225,9227,9229,9231,9234,9236],{"class":90,"line":122},[88,9218,132],{"class":98},[88,9220,136],{"class":135},[88,9222,139],{"class":98},[88,9224,143],{"class":142},[88,9226,147],{"class":146},[88,9228,150],{"class":142},[88,9230,154],{"class":153},[88,9232,9233],{"class":157},"data\u002Fbuildings.gpkg",[88,9235,154],{"class":153},[88,9237,163],{"class":142},[88,9239,9240,9242,9244,9246,9248,9250,9253,9255,9257,9259,9261,9263,9265,9267],{"class":90,"line":129},[88,9241,182],{"class":98},[88,9243,143],{"class":142},[88,9245,354],{"class":146},[88,9247,150],{"class":142},[88,9249,154],{"class":153},[88,9251,9252],{"class":157},"output\u002Fbuildings.geojson",[88,9254,154],{"class":153},[88,9256,212],{"class":142},[88,9258,369],{"class":368},[88,9260,136],{"class":135},[88,9262,154],{"class":153},[88,9264,1741],{"class":157},[88,9266,154],{"class":153},[88,9268,163],{"class":142},[397,9270,9272],{"id":9271},"example-2-read-a-shapefile-and-convert-it-to-geojson","Example 2: Read a shapefile and convert it to GeoJSON",[16,9274,9275],{},"This is a practical shapefile-to-GeoJSON conversion.",[79,9277,9279],{"className":81,"code":9278,"language":83,"meta":84,"style":84},"import geopandas as gpd\n\ngdf = gpd.read_file(\"data\u002Froads.shp\")\ngdf.to_file(\"output\u002Froads.geojson\", driver=\"GeoJSON\")\n",[52,9280,9281,9291,9295,9317],{"__ignoreMap":84},[88,9282,9283,9285,9287,9289],{"class":90,"line":91},[88,9284,95],{"class":94},[88,9286,99],{"class":98},[88,9288,102],{"class":94},[88,9290,105],{"class":98},[88,9292,9293],{"class":90,"line":108},[88,9294,126],{"emptyLinePlaceholder":125},[88,9296,9297,9299,9301,9303,9305,9307,9309,9311,9313,9315],{"class":90,"line":122},[88,9298,132],{"class":98},[88,9300,136],{"class":135},[88,9302,139],{"class":98},[88,9304,143],{"class":142},[88,9306,147],{"class":146},[88,9308,150],{"class":142},[88,9310,154],{"class":153},[88,9312,2831],{"class":157},[88,9314,154],{"class":153},[88,9316,163],{"class":142},[88,9318,9319,9321,9323,9325,9327,9329,9331,9333,9335,9337,9339,9341,9343,9345],{"class":90,"line":129},[88,9320,182],{"class":98},[88,9322,143],{"class":142},[88,9324,354],{"class":146},[88,9326,150],{"class":142},[88,9328,154],{"class":153},[88,9330,8706],{"class":157},[88,9332,154],{"class":153},[88,9334,212],{"class":142},[88,9336,369],{"class":368},[88,9338,136],{"class":135},[88,9340,154],{"class":153},[88,9342,1741],{"class":157},[88,9344,154],{"class":153},[88,9346,163],{"class":142},[16,9348,9349],{},"This is one of the most common cases when users want to convert a shapefile to GeoJSON in Python.",[397,9351,9353],{"id":9352},"example-3-reproject-to-epsg4326-before-export","Example 3: Reproject to EPSG:4326 before export",[16,9355,9356],{},"If the input data is in a projected CRS, convert it before writing GeoJSON.",[79,9358,9360],{"className":81,"code":9359,"language":83,"meta":84,"style":84},"import geopandas as gpd\n\ngdf = gpd.read_file(\"data\u002Fzoning.shp\")\n\nprint(\"Original CRS:\", gdf.crs)\n\ngdf_wgs84 = gdf.to_crs(\"EPSG:4326\")\ngdf_wgs84.to_file(\"output\u002Fzoning_wgs84.geojson\", driver=\"GeoJSON\")\n",[52,9361,9362,9372,9376,9399,9403,9426,9430,9453],{"__ignoreMap":84},[88,9363,9364,9366,9368,9370],{"class":90,"line":91},[88,9365,95],{"class":94},[88,9367,99],{"class":98},[88,9369,102],{"class":94},[88,9371,105],{"class":98},[88,9373,9374],{"class":90,"line":108},[88,9375,126],{"emptyLinePlaceholder":125},[88,9377,9378,9380,9382,9384,9386,9388,9390,9392,9395,9397],{"class":90,"line":122},[88,9379,132],{"class":98},[88,9381,136],{"class":135},[88,9383,139],{"class":98},[88,9385,143],{"class":142},[88,9387,147],{"class":146},[88,9389,150],{"class":142},[88,9391,154],{"class":153},[88,9393,9394],{"class":157},"data\u002Fzoning.shp",[88,9396,154],{"class":153},[88,9398,163],{"class":142},[88,9400,9401],{"class":90,"line":129},[88,9402,126],{"emptyLinePlaceholder":125},[88,9404,9405,9407,9409,9411,9414,9416,9418,9420,9422,9424],{"class":90,"line":166},[88,9406,454],{"class":453},[88,9408,150],{"class":142},[88,9410,154],{"class":153},[88,9412,9413],{"class":157},"Original CRS:",[88,9415,154],{"class":153},[88,9417,212],{"class":142},[88,9419,228],{"class":146},[88,9421,143],{"class":142},[88,9423,463],{"class":187},[88,9425,163],{"class":142},[88,9427,9428],{"class":90,"line":171},[88,9429,126],{"emptyLinePlaceholder":125},[88,9431,9432,9435,9437,9439,9441,9443,9445,9447,9449,9451],{"class":90,"line":196},[88,9433,9434],{"class":98},"gdf_wgs84 ",[88,9436,136],{"class":135},[88,9438,228],{"class":98},[88,9440,143],{"class":142},[88,9442,4481],{"class":146},[88,9444,150],{"class":142},[88,9446,154],{"class":153},[88,9448,4125],{"class":157},[88,9450,154],{"class":153},[88,9452,163],{"class":142},[88,9454,9455,9458,9460,9462,9464,9466,9469,9471,9473,9475,9477,9479,9481,9483],{"class":90,"line":260},[88,9456,9457],{"class":98},"gdf_wgs84",[88,9459,143],{"class":142},[88,9461,354],{"class":146},[88,9463,150],{"class":142},[88,9465,154],{"class":153},[88,9467,9468],{"class":157},"output\u002Fzoning_wgs84.geojson",[88,9470,154],{"class":153},[88,9472,212],{"class":142},[88,9474,369],{"class":368},[88,9476,136],{"class":135},[88,9478,154],{"class":153},[88,9480,1741],{"class":157},[88,9482,154],{"class":153},[88,9484,163],{"class":142},[16,9486,9487],{},"This is the recommended pattern for web mapping workflows.",[397,9489,9491],{"id":9490},"example-4-export-only-selected-columns-and-features","Example 4: Export only selected columns and features",[16,9493,9494],{},"You can filter rows and keep only the fields you need before saving.",[79,9496,9498],{"className":81,"code":9497,"language":83,"meta":84,"style":84},"import geopandas as gpd\n\ngdf = gpd.read_file(\"data\u002Fparcels.shp\")\n\nfiltered = gdf[gdf[\"land_use\"] == \"residential\"][[\"parcel_id\", \"owner\", \"geometry\"]]\nfiltered = filtered.to_crs(\"EPSG:4326\")\n\nfiltered.to_file(\"output\u002Fresidential_parcels.geojson\", driver=\"GeoJSON\")\n",[52,9499,9500,9510,9514,9536,9540,9602,9625,9629],{"__ignoreMap":84},[88,9501,9502,9504,9506,9508],{"class":90,"line":91},[88,9503,95],{"class":94},[88,9505,99],{"class":98},[88,9507,102],{"class":94},[88,9509,105],{"class":98},[88,9511,9512],{"class":90,"line":108},[88,9513,126],{"emptyLinePlaceholder":125},[88,9515,9516,9518,9520,9522,9524,9526,9528,9530,9532,9534],{"class":90,"line":122},[88,9517,132],{"class":98},[88,9519,136],{"class":135},[88,9521,139],{"class":98},[88,9523,143],{"class":142},[88,9525,147],{"class":146},[88,9527,150],{"class":142},[88,9529,154],{"class":153},[88,9531,158],{"class":157},[88,9533,154],{"class":153},[88,9535,163],{"class":142},[88,9537,9538],{"class":90,"line":129},[88,9539,126],{"emptyLinePlaceholder":125},[88,9541,9542,9545,9547,9549,9551,9553,9555,9557,9560,9562,9564,9567,9569,9572,9574,9577,9579,9581,9583,9585,9587,9590,9592,9594,9596,9598,9600],{"class":90,"line":166},[88,9543,9544],{"class":98},"filtered ",[88,9546,136],{"class":135},[88,9548,228],{"class":98},[88,9550,206],{"class":142},[88,9552,182],{"class":98},[88,9554,206],{"class":142},[88,9556,154],{"class":153},[88,9558,9559],{"class":157},"land_use",[88,9561,154],{"class":153},[88,9563,222],{"class":142},[88,9565,9566],{"class":135}," ==",[88,9568,215],{"class":153},[88,9570,9571],{"class":157},"residential",[88,9573,154],{"class":153},[88,9575,9576],{"class":142},"][[",[88,9578,154],{"class":153},[88,9580,7787],{"class":157},[88,9582,154],{"class":153},[88,9584,212],{"class":142},[88,9586,215],{"class":153},[88,9588,9589],{"class":157},"owner",[88,9591,154],{"class":153},[88,9593,212],{"class":142},[88,9595,215],{"class":153},[88,9597,188],{"class":157},[88,9599,154],{"class":153},[88,9601,608],{"class":142},[88,9603,9604,9606,9608,9611,9613,9615,9617,9619,9621,9623],{"class":90,"line":171},[88,9605,9544],{"class":98},[88,9607,136],{"class":135},[88,9609,9610],{"class":98}," filtered",[88,9612,143],{"class":142},[88,9614,4481],{"class":146},[88,9616,150],{"class":142},[88,9618,154],{"class":153},[88,9620,4125],{"class":157},[88,9622,154],{"class":153},[88,9624,163],{"class":142},[88,9626,9627],{"class":90,"line":196},[88,9628,126],{"emptyLinePlaceholder":125},[88,9630,9631,9634,9636,9638,9640,9642,9645,9647,9649,9651,9653,9655,9657,9659],{"class":90,"line":260},[88,9632,9633],{"class":98},"filtered",[88,9635,143],{"class":142},[88,9637,354],{"class":146},[88,9639,150],{"class":142},[88,9641,154],{"class":153},[88,9643,9644],{"class":157},"output\u002Fresidential_parcels.geojson",[88,9646,154],{"class":153},[88,9648,212],{"class":142},[88,9650,369],{"class":368},[88,9652,136],{"class":135},[88,9654,154],{"class":153},[88,9656,1741],{"class":157},[88,9658,154],{"class":153},[88,9660,163],{"class":142},[16,9662,9663],{},"This is useful when you want a smaller, cleaner output for sharing or web use.",[11,9665,2483],{"id":2482},[16,9667,9668,9669,9671,9672,143],{},"When you call ",[52,9670,8621],{},", GeoPandas writes vector data using the file driver you specify. For GeoJSON output, that driver is ",[52,9673,1741],{},[16,9675,9676,9677,9679],{},"In practical GeoPandas workflows, ",[52,9678,9034],{}," is the standard method for writing formats such as:",[23,9681,9682,9685,9688],{},[26,9683,9684],{},"Shapefile",[26,9686,9687],{},"GeoPackage",[26,9689,1741],{},[16,9691,9692],{},"The driver tells GeoPandas which file format to create.",[16,9694,9695],{},"CRS matters because GeoJSON is commonly consumed by tools that expect longitude and latitude coordinates in WGS84. If you export projected coordinates without checking CRS, the file may still write successfully, but it may display in the wrong place or fail in some web tools.",[16,9697,9698],{},"Attribute fields matter too. Simple text, numbers, and dates usually work well. More complex values, such as nested Python objects or inconsistent types in a column, can cause problems during export or when the file is opened elsewhere.",[16,9700,9701],{},"Geometry quality also matters. Invalid polygons, empty geometries, or mixed geometry types may still write, but can create issues in QGIS, web maps, or spatial APIs.",[11,9703,2553],{"id":2552},[397,9705,9707],{"id":9706},"file-already-exists","File already exists",[16,9709,9710],{},"If the output file already exists, do not assume overwrite behavior will be handled the way you want. For predictable results, remove the old file first if that fits your workflow.",[79,9712,9714],{"className":81,"code":9713,"language":83,"meta":84,"style":84},"from pathlib import Path\nimport geopandas as gpd\n\noutput_file = Path(\"output\u002Froads.geojson\")\n\nif output_file.exists():\n    output_file.unlink()\n\ngdf = gpd.read_file(\"data\u002Froads.shp\")\ngdf.to_file(output_file, driver=\"GeoJSON\")\n",[52,9715,9716,9726,9736,9740,9758,9762,9775,9787,9791,9813],{"__ignoreMap":84},[88,9717,9718,9720,9722,9724],{"class":90,"line":91},[88,9719,111],{"class":94},[88,9721,3282],{"class":98},[88,9723,95],{"class":94},[88,9725,3287],{"class":98},[88,9727,9728,9730,9732,9734],{"class":90,"line":108},[88,9729,95],{"class":94},[88,9731,99],{"class":98},[88,9733,102],{"class":94},[88,9735,105],{"class":98},[88,9737,9738],{"class":90,"line":122},[88,9739,126],{"emptyLinePlaceholder":125},[88,9741,9742,9744,9746,9748,9750,9752,9754,9756],{"class":90,"line":129},[88,9743,9047],{"class":98},[88,9745,136],{"class":135},[88,9747,3310],{"class":146},[88,9749,150],{"class":142},[88,9751,154],{"class":153},[88,9753,8706],{"class":157},[88,9755,154],{"class":153},[88,9757,163],{"class":142},[88,9759,9760],{"class":90,"line":166},[88,9761,126],{"emptyLinePlaceholder":125},[88,9763,9764,9766,9769,9771,9773],{"class":90,"line":171},[88,9765,3871],{"class":94},[88,9767,9768],{"class":98}," output_file",[88,9770,143],{"class":142},[88,9772,3882],{"class":146},[88,9774,2050],{"class":142},[88,9776,9777,9780,9782,9785],{"class":90,"line":196},[88,9778,9779],{"class":98},"    output_file",[88,9781,143],{"class":142},[88,9783,9784],{"class":146},"unlink",[88,9786,759],{"class":142},[88,9788,9789],{"class":90,"line":260},[88,9790,126],{"emptyLinePlaceholder":125},[88,9792,9793,9795,9797,9799,9801,9803,9805,9807,9809,9811],{"class":90,"line":265},[88,9794,132],{"class":98},[88,9796,136],{"class":135},[88,9798,139],{"class":98},[88,9800,143],{"class":142},[88,9802,147],{"class":146},[88,9804,150],{"class":142},[88,9806,154],{"class":153},[88,9808,2831],{"class":157},[88,9810,154],{"class":153},[88,9812,163],{"class":142},[88,9814,9815,9817,9819,9821,9823,9825,9827,9829,9831,9833,9835,9837],{"class":90,"line":290},[88,9816,182],{"class":98},[88,9818,143],{"class":142},[88,9820,354],{"class":146},[88,9822,150],{"class":142},[88,9824,9069],{"class":146},[88,9826,212],{"class":142},[88,9828,369],{"class":368},[88,9830,136],{"class":135},[88,9832,154],{"class":153},[88,9834,1741],{"class":157},[88,9836,154],{"class":153},[88,9838,163],{"class":142},[397,9840,9842],{"id":9841},"crs-is-missing","CRS is missing",[16,9844,1110,9845,4090,9847,9849],{},[52,9846,4089],{},[52,9848,4093],{},", the data has no defined CRS.",[79,9851,9852],{"className":81,"code":3138,"language":83,"meta":84,"style":84},[52,9853,9854],{"__ignoreMap":84},[88,9855,9856,9858,9860,9862,9864,9866],{"class":90,"line":91},[88,9857,454],{"class":453},[88,9859,150],{"class":142},[88,9861,182],{"class":146},[88,9863,143],{"class":142},[88,9865,463],{"class":187},[88,9867,163],{"class":142},[16,9869,9870],{},"That does not always stop export, but it creates confusion later. Set the CRS only if you know what the source coordinates represent.",[79,9872,9874],{"className":81,"code":9873,"language":83,"meta":84,"style":84},"gdf = gdf.set_crs(\"EPSG:32633\")\n",[52,9875,9876],{"__ignoreMap":84},[88,9877,9878,9880,9882,9884,9886,9888,9890,9892,9895,9897],{"class":90,"line":91},[88,9879,132],{"class":98},[88,9881,136],{"class":135},[88,9883,228],{"class":98},[88,9885,143],{"class":142},[88,9887,4118],{"class":146},[88,9889,150],{"class":142},[88,9891,154],{"class":153},[88,9893,9894],{"class":157},"EPSG:32633",[88,9896,154],{"class":153},[88,9898,163],{"class":142},[397,9900,4136],{"id":4135},[16,9902,9903],{},"Broken geometries can cause export or display problems.",[79,9905,9907],{"className":81,"code":9906,"language":83,"meta":84,"style":84},"invalid_count = (~gdf.geometry.is_valid).sum()\nprint(\"Invalid geometries:\", invalid_count)\n",[52,9908,9909,9936],{"__ignoreMap":84},[88,9910,9911,9914,9916,9918,9920,9922,9924,9926,9928,9930,9932,9934],{"class":90,"line":91},[88,9912,9913],{"class":98},"invalid_count ",[88,9915,136],{"class":135},[88,9917,1054],{"class":142},[88,9919,301],{"class":135},[88,9921,182],{"class":98},[88,9923,143],{"class":142},[88,9925,188],{"class":187},[88,9927,143],{"class":142},[88,9929,337],{"class":187},[88,9931,1266],{"class":142},[88,9933,1072],{"class":146},[88,9935,759],{"class":142},[88,9937,9938,9940,9942,9944,9947,9949,9951,9954],{"class":90,"line":108},[88,9939,454],{"class":453},[88,9941,150],{"class":142},[88,9943,154],{"class":153},[88,9945,9946],{"class":157},"Invalid geometries:",[88,9948,154],{"class":153},[88,9950,212],{"class":142},[88,9952,9953],{"class":146}," invalid_count",[88,9955,163],{"class":142},[16,9957,9958],{},"If needed, you can try repairing geometries before export:",[79,9960,9962],{"className":81,"code":9961,"language":83,"meta":84,"style":84},"gdf[\"geometry\"] = gdf.buffer(0)\n",[52,9963,9964],{"__ignoreMap":84},[88,9965,9966,9968,9970,9972,9974,9976,9978,9980,9982,9984,9986,9988,9990],{"class":90,"line":91},[88,9967,182],{"class":98},[88,9969,206],{"class":142},[88,9971,154],{"class":153},[88,9973,188],{"class":157},[88,9975,154],{"class":153},[88,9977,222],{"class":142},[88,9979,225],{"class":135},[88,9981,228],{"class":98},[88,9983,143],{"class":142},[88,9985,1215],{"class":146},[88,9987,150],{"class":142},[88,9989,1220],{"class":822},[88,9991,163],{"class":142},[16,9993,9994],{},"This workaround sometimes helps, especially with polygon issues, but it can change geometry and does not fix every problem.",[397,9996,9998],{"id":9997},"large-files","Large files",[16,10000,10001],{},"GeoJSON is text-based and can become large and slow with many features. It is good for sharing and web delivery, but not always the best format for heavy processing. For large datasets, consider GeoPackage or Parquet for internal workflows.",[397,10003,10005],{"id":10004},"attribute-field-compatibility","Attribute field compatibility",[16,10007,10008],{},"Avoid exporting columns that contain:",[23,10010,10011,10014,10017],{},[26,10012,10013],{},"lists or dictionaries",[26,10015,10016],{},"mixed Python object types",[26,10018,10019],{},"values you do not need",[16,10021,10022],{},"A smaller attribute table usually produces a more compatible GeoJSON file.",[11,10024,2612],{"id":2611},[16,10026,10027,10028,143],{},"If you need background first, see ",[2617,10029,4198],{"href":4197},[16,10031,8370],{},[23,10033,10034,10038],{},[26,10035,10036],{},[2617,10037,2631],{"href":2630},[26,10039,10040],{},[2617,10041,4205],{"href":4204},[16,10043,10044,10045,143],{},"If export is failing, check ",[2617,10046,10047],{"href":2636},"Why GeoPandas to_file Is Not Writing the Output File",[11,10049,2647],{"id":2646},[397,10051,10053],{"id":10052},"how-do-i-export-a-geodataframe-to-geojson-in-geopandas","How do I export a GeoDataFrame to GeoJSON in GeoPandas?",[16,10055,383,10056,10058],{},[52,10057,9034],{}," with the GeoJSON driver:",[79,10060,10062],{"className":81,"code":10061,"language":83,"meta":84,"style":84},"gdf.to_file(\"output\u002Fdata.geojson\", driver=\"GeoJSON\")\n",[52,10063,10064],{"__ignoreMap":84},[88,10065,10066,10068,10070,10072,10074,10076,10079,10081,10083,10085,10087,10089,10091,10093],{"class":90,"line":91},[88,10067,182],{"class":98},[88,10069,143],{"class":142},[88,10071,354],{"class":146},[88,10073,150],{"class":142},[88,10075,154],{"class":153},[88,10077,10078],{"class":157},"output\u002Fdata.geojson",[88,10080,154],{"class":153},[88,10082,212],{"class":142},[88,10084,369],{"class":368},[88,10086,136],{"class":135},[88,10088,154],{"class":153},[88,10090,1741],{"class":157},[88,10092,154],{"class":153},[88,10094,163],{"class":142},[16,10096,10097],{},"That is the standard GeoPandas method to write GeoJSON from a GeoDataFrame.",[397,10099,10101],{"id":10100},"do-i-need-to-convert-my-crs-to-epsg4326-before-saving-geojson","Do I need to convert my CRS to EPSG:4326 before saving GeoJSON?",[16,10103,10104,10105,10107],{},"Not always, but it is strongly recommended for web maps and many APIs. ",[52,10106,4125],{}," is the most interoperable choice for GeoJSON.",[79,10109,10111],{"className":81,"code":10110,"language":83,"meta":84,"style":84},"gdf = gdf.to_crs(\"EPSG:4326\")\n",[52,10112,10113],{"__ignoreMap":84},[88,10114,10115,10117,10119,10121,10123,10125,10127,10129,10131,10133],{"class":90,"line":91},[88,10116,132],{"class":98},[88,10118,136],{"class":135},[88,10120,228],{"class":98},[88,10122,143],{"class":142},[88,10124,4481],{"class":146},[88,10126,150],{"class":142},[88,10128,154],{"class":153},[88,10130,4125],{"class":157},[88,10132,154],{"class":153},[88,10134,163],{"class":142},[397,10136,10138],{"id":10137},"can-i-convert-a-shapefile-to-geojson-with-geopandas","Can I convert a shapefile to GeoJSON with GeoPandas?",[16,10140,10141],{},"Yes. Read the shapefile, then write it as GeoJSON.",[79,10143,10145],{"className":81,"code":10144,"language":83,"meta":84,"style":84},"gdf = gpd.read_file(\"data\u002Finput.shp\")\ngdf.to_file(\"output\u002Foutput.geojson\", driver=\"GeoJSON\")\n",[52,10146,10147,10170],{"__ignoreMap":84},[88,10148,10149,10151,10153,10155,10157,10159,10161,10163,10166,10168],{"class":90,"line":91},[88,10150,132],{"class":98},[88,10152,136],{"class":135},[88,10154,139],{"class":98},[88,10156,143],{"class":142},[88,10158,147],{"class":146},[88,10160,150],{"class":142},[88,10162,154],{"class":153},[88,10164,10165],{"class":157},"data\u002Finput.shp",[88,10167,154],{"class":153},[88,10169,163],{"class":142},[88,10171,10172,10174,10176,10178,10180,10182,10185,10187,10189,10191,10193,10195,10197,10199],{"class":90,"line":108},[88,10173,182],{"class":98},[88,10175,143],{"class":142},[88,10177,354],{"class":146},[88,10179,150],{"class":142},[88,10181,154],{"class":153},[88,10183,10184],{"class":157},"output\u002Foutput.geojson",[88,10186,154],{"class":153},[88,10188,212],{"class":142},[88,10190,369],{"class":368},[88,10192,136],{"class":135},[88,10194,154],{"class":153},[88,10196,1741],{"class":157},[88,10198,154],{"class":153},[88,10200,163],{"class":142},[397,10202,10204],{"id":10203},"why-is-my-exported-geojson-not-opening-correctly-in-qgis-or-a-web-map","Why is my exported GeoJSON not opening correctly in QGIS or a web map?",[16,10206,8490],{},[23,10208,10209,10212,10215,10218],{},[26,10210,10211],{},"wrong or missing CRS",[26,10213,10214],{},"invalid geometries",[26,10216,10217],{},"unsupported attribute values",[26,10219,10220],{},"corrupted or incomplete output path",[16,10222,10223],{},"Check the CRS, validate geometries, and try reading the exported file back into GeoPandas.",[2693,10225,10226],{},"html pre.shiki code .sVHd0, html code.shiki .sVHd0{--shiki-light:#39ADB5;--shiki-light-font-style:italic;--shiki-default:#D73A49;--shiki-default-font-style:inherit;--shiki-dark:#F97583;--shiki-dark-font-style:inherit}html pre.shiki code .su5hD, html code.shiki .su5hD{--shiki-light:#90A4AE;--shiki-default:#24292E;--shiki-dark:#E1E4E8}html pre.shiki code .smGrS, html code.shiki .smGrS{--shiki-light:#39ADB5;--shiki-default:#D73A49;--shiki-dark:#F97583}html pre.shiki code .sP7_E, html code.shiki .sP7_E{--shiki-light:#39ADB5;--shiki-default:#24292E;--shiki-dark:#E1E4E8}html pre.shiki code .slqww, html code.shiki .slqww{--shiki-light:#6182B8;--shiki-default:#24292E;--shiki-dark:#E1E4E8}html pre.shiki code .sjJ54, html code.shiki .sjJ54{--shiki-light:#39ADB5;--shiki-default:#032F62;--shiki-dark:#9ECBFF}html pre.shiki code .s_sjI, html code.shiki .s_sjI{--shiki-light:#91B859;--shiki-default:#032F62;--shiki-dark:#9ECBFF}html pre.shiki code .sutJx, html code.shiki .sutJx{--shiki-light:#90A4AE;--shiki-light-font-style:italic;--shiki-default:#6A737D;--shiki-default-font-style:inherit;--shiki-dark:#6A737D;--shiki-dark-font-style:inherit}html pre.shiki code .s99_P, html code.shiki .s99_P{--shiki-light:#90A4AE;--shiki-light-font-style:italic;--shiki-default:#E36209;--shiki-default-font-style:inherit;--shiki-dark:#FFAB70;--shiki-dark-font-style:inherit}html .light .shiki span {color: var(--shiki-light);background: var(--shiki-light-bg);font-style: var(--shiki-light-font-style);font-weight: var(--shiki-light-font-weight);text-decoration: var(--shiki-light-text-decoration);}html.light .shiki span {color: var(--shiki-light);background: var(--shiki-light-bg);font-style: var(--shiki-light-font-style);font-weight: var(--shiki-light-font-weight);text-decoration: var(--shiki-light-text-decoration);}html .default .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html.dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html pre.shiki code .sptTA, html code.shiki .sptTA{--shiki-light:#6182B8;--shiki-default:#005CC5;--shiki-dark:#79B8FF}html pre.shiki code .sZMiF, html code.shiki .sZMiF{--shiki-light:#E2931D;--shiki-default:#005CC5;--shiki-dark:#79B8FF}html pre.shiki code .skxfh, html code.shiki .skxfh{--shiki-light:#E53935;--shiki-default:#24292E;--shiki-dark:#E1E4E8}html pre.shiki code .srdBf, html code.shiki .srdBf{--shiki-light:#F76D47;--shiki-default:#005CC5;--shiki-dark:#79B8FF}",{"title":84,"searchDepth":108,"depth":108,"links":10228},[10229,10230,10231,10238,10244,10245,10252,10253],{"id":13,"depth":108,"text":14},{"id":73,"depth":108,"text":74},{"id":394,"depth":108,"text":395,"children":10232},[10233,10234,10235,10236,10237],{"id":8753,"depth":122,"text":8754},{"id":8852,"depth":122,"text":8853},{"id":8957,"depth":122,"text":8958},{"id":9028,"depth":122,"text":9029},{"id":9094,"depth":122,"text":9095},{"id":1781,"depth":108,"text":1782,"children":10239},[10240,10241,10242,10243],{"id":9191,"depth":122,"text":9192},{"id":9271,"depth":122,"text":9272},{"id":9352,"depth":122,"text":9353},{"id":9490,"depth":122,"text":9491},{"id":2482,"depth":108,"text":2483},{"id":2552,"depth":108,"text":2553,"children":10246},[10247,10248,10249,10250,10251],{"id":9706,"depth":122,"text":9707},{"id":9841,"depth":122,"text":9842},{"id":4135,"depth":122,"text":4136},{"id":9997,"depth":122,"text":9998},{"id":10004,"depth":122,"text":10005},{"id":2611,"depth":108,"text":2612},{"id":2646,"depth":108,"text":2647,"children":10254},[10255,10256,10257,10258],{"id":10052,"depth":122,"text":10053},{"id":10100,"depth":122,"text":10101},{"id":10137,"depth":122,"text":10138},{"id":10203,"depth":122,"text":10204},"How to export a GeoDataFrame to GeoJSON in Python using GeoPandas, with driver options and output examples.",{},"\u002Ftasks\u002Fwrite-geojson-python",{"title":2637,"description":10259},"tasks\u002Fwrite-geojson-python","F9kM7d6e3geDDCzQBTdun3gps40wyUN_kh4J9Ek3Ks4",1776966205539]