0

I have a boundary with polygon object that is consisted of longitudes and latitudes.

That looks like the below:

POLYGON((35.82879102266901 128.7076346641539,35.82707300496909 128.7067790195541,35.82583849984275 128.70867790735832,35.824475124668446 128.70759751110955,35.823661363692246 128.7058871623279,35.82330557322746 128.70555866952947,35.82331389280524 128.70497241578087,35.82526251082479 128.70418422540567,35.82744337671204 128.7041755355518,35.827607540680496 128.70530771172315,35.82939029995311 128.70541225682194,35.83034001648074 128.70262188794626,35.83078056043854 128.69951074704943,35.83193366058302 128.69379210686643,35.828047660143625 128.693941879719,35.827966675973194 128.69201477525812,35.82756567015862 128.691054639399,35.82742778802447 128.68932551896413,35.82650612209906 128.6882215894989,35.82623275962891 128.6871535405911,35.82647878660091 128.68631779206828,35.82589756010733 128.6853538910315,35.82655549313656 128.68470389060354,35.82708326990368 128.6843388272404,35.82758369093474 128.68335351964126,35.82889524063444 128.68364679883342,35.82890639831895 128.68285031370743,35.828906097221974 128.67981280809806,35.82888304950931 128.67888281424953,35.82896109865986 128.67781109698095,35.82914226525198 128.6749987130506,35.829530458483134 128.66911993413487,35.82983133640095 128.66821884727412,35.83362553735145 128.67013528497822,35.834399059357544 128.67024003096986,35.840482024092296 128.6695707366228,35.84159664755783 128.66977117810666,35.842905155774766 128.67028558214335,35.84594503638666 128.67200953129984,35.84644751771214 128.67086900635903,35.84705457008395 128.6712801954765,35.8434163977168 128.67886262656154,35.84314479314578 128.67975890696695,35.84173465446248 128.6852185741404,35.84220901183875 128.68737568860865,35.842691108354394 128.68897961865747,35.84312006520884 128.69051603468242,35.84319021489896 128.6919341686762,35.843845826650806 128.69193149502144,35.84458126183942 128.69217954131344,35.8450944094251 128.6928545128021,35.845537407773186 128.6949889588373,35.84594458681003 128.69774246767017,35.84595753555761 128.69873885574475,35.845592497537034 128.69906310486897,35.8455682983552 128.69949976886403,35.8456150311943 128.70001818866905,35.845563157388696 128.70065901677296,35.84537908872975 128.70140769814486,35.84555437110258 128.70286963195795,35.84587322292093 128.70357926102878,35.84594642214659 128.70381878675977,35.846971713667784 128.70522976267594,35.847545984299884 128.70540254780536,35.84770419707187 128.70647677872364,35.846993881550205 128.70668291781934,35.84665150163529 128.70699655180104,35.84651270074719 128.70756911108555,35.84664594398947 128.708338426456,35.846370809343775 128.70867563064274,35.84552164493595 128.70882342843882,35.84555869274497 128.7100195496374,35.844390635774545 128.70946322074195,35.84409546436334 128.71057471572104,35.84279576302751 128.7119855691835,35.84233078727481 128.71173209213836,35.84162880715499 128.71356524195375,35.84170215924991 128.71473995285587,35.8416923687089 128.7160567492122,35.84125948431006 128.71671145609938,35.84060185802347 128.717328108808,35.83969799283258 128.71814971377495,35.840034447448154 128.71919727395152,35.83991953670813 128.71967067618365,35.84008465778431 128.72072561124943,35.841207493858356 128.72223287429418,35.8400990619929 128.72349268565964,35.84077048506402 128.72505661382988,35.84092818918439 128.72536990992046,35.84112033710699 128.7257946253903,35.84131958422449 128.7263523033404,35.84147458147238 128.72685368846388,35.83911513549549 128.7286285758717,35.839407843897376 128.72926574390837,35.833677521275426 128.73295917806223,35.82998596835267 128.73274610143017,35.82643232778233 128.73109204987105,35.82124747076703 128.73101263135672,35.81720051067774 128.73357454481362,35.81238647159309 128.73589823930334,35.808559429329115 128.73695438018242,35.80941040679152 128.73325029582915,35.81056065279409 128.72909350975036,35.81459078638608 128.72518698632229,35.81992126286518 128.71793355529508,35.82191863521933 128.71689227991428,35.82393401644843 128.71585134191892,35.82522489120707 128.71379891405198,35.82756633550083 128.71010918623398,35.82879102266901 128.7076346641539))

I also have a list of sets of longitudes and latitudes.

df = pd.DataFrame({'name':['a', 'b', 'c', 'd'] ,'lat': [37.6647124, 37.90052166666667, 36.807616, 37.24141], 'long': [126.7686911, 127.203435, 127.107547, 127.059358]})

I want to filter out names that are not within the polygon.

I can't come up with an idea that works.

[Edited] For the POLYGON, if you need to convert that to a list of pairs, then you can use the following code.

def get_lat_lng_pair(boundary_str):
    lat_lng_list = []
    for lat_lng_str in boundary_str.split(','):
        lat, lng = lat_lng_str.split()
        lat_lng_list.append((float(lat), float(lng)))
    return lat_lng_list

# Extracting All Polygon points
all_area_ids = [27]
all_polygon_pts = get_all_polygon_pts(area_df, all_area_ids)
all_polygon_pts
Yun Tae Hwang
  • 1,249
  • 3
  • 18
  • 30
  • There is a Wikipedia article, [Point in Polygon](https://en.wikipedia.org/wiki/Point_in_polygon) that presents several methods of doing this. What have you tried? How were the results not what you expected? – The Photon Dec 29 '22 at 04:32
  • 1
    Also, did you read [What's the fastest way of checking if a point is inside a polygon in python](https://stackoverflow.com/q/36399381/1630971)? – The Photon Dec 29 '22 at 04:35
  • If the previous answers aren't applicable, you need to explain the special requirements of your situation that make them not applicable. – The Photon Dec 29 '22 at 04:40

0 Answers0