I am very new to python so struggling! I have lat long coordinates for circles that I need to turn into a polygon shapefile from the current format (example shown of one circle):
[(39.1852751477193, -4.661967433717266), (39.185270807935424, -4.6620560715526205),
(39.18525783015025, -4.6621438557678925), (39.18523633934382, -4.662229940952642),
(39.18520654248149, -4.66231349805872), (39.185168726520814, -4.662393722384509),
(39.1851232556481, -4.662469841324661), (39.185070567771184, -4.662541121810758),
(39.18501117030217, -4.6626068773712275), (39.184945635270836, -4.662666474742481),
(39.184874593815685, -4.662719339967662), (39.1847987301057, -4.662764963924225),
(39.18471877475142, -4.662802907227118), (39.18463549776867, -4.662832804460353),
(39.18454970116283, -4.662854367696218), (39.184462211205, -4.662867389268209),
(39.1843738704744, -4.662871743771006), (39.1842855297438, -4.662867389268209),
(39.184198039785976, -4.662854367696218), (39.18411224318014, -4.662832804460353),
(39.18402896619739, -4.662802907227118), (39.18394901084311, -4.662764963924225),
(39.18387314713312, -4.662719339967661), (39.18380210567796, -4.662666474742481),
(39.18373657064664, -4.6626068773712275), (39.18367717317762, -4.662541121810758),
(39.183624485300705, -4.662469841324661), (39.18357901442799, -4.662393722384509),
(39.18354119846732, -4.662313498058719), (39.18351140160499, -4.662229940952642),
(39.183489910798556, -4.6621438557678925), (39.18347693301339, -4.6620560715526205),
(39.1834725932295, -4.661967433717266), (39.18347693323819, -4.661878795892798),
(39.183489911239526, -4.661791011709759), (39.183511402245166, -4.661704926577361),
(39.18354119928211, -4.661621369541729), (39.18357901538609, -4.66154114530178),
(39.18362448636528, -4.661465026459563), (39.18367717430777, -4.661393746079731),
(39.183736571798924, -4.661327990629777), (39.183802106808116, -4.6612683933690375),
(39.1838731481977, -4.661215528250123), (39.183949011801204, -4.661169904391494),
(39.18402896701218, -4.661131961174444), (39.184112243820316, -4.661102064011655),
(39.18419804022694, -4.661080500828139), (39.184285529968605, -4.661067479288384),
(39.1843738704744, -4.6610631247964704), (39.1844622109802, -4.661067479288384),
(39.18454970072187, -4.66108050082814), (39.18463549712849, -4.661102064011656),
(39.18471877393662, -4.661131961174444), (39.1847987291476, -4.661169904391494),
(39.18487459275111, -4.661215528250122), (39.18494563414069, -4.6612683933690375),
(39.18501116914988, -4.661327990629778), (39.18507056664104, -4.661393746079731),
(39.18512325458352, -4.661465026459563), (39.18516872556272, -4.66154114530178),
(39.185206541666695, -4.661621369541729), (39.18523633870364, -4.66170492657736),
(39.18525782970928, -4.661791011709759), (39.185270807710616, -4.661878795892798),
(39.1852751477193, -4.661967433717266)]
I have tried the code suggested by pyshp documentation but I cannot even get the test version to run:
import shapefile
w = shapefile.Writer(shapefile.POLYGON)
w.poly(parts=[[[1,5],[5,5],[5,1],[3,3],[1,1]]])
w.field('FIRST_FLD','C','40')
w.field('SECOND_FLD','C','40')
w.record('First','Polygon')
w.save('shapefiles/test/polygon')
I then tried the solution suggested on a similar problem: I cannot manage to export coordinates to a shapefile using Python. Is there a problem in my code or might the problem lie in the module?
which was:
shapefile.Writer() expects the filename as first parameter, so what you mean is probably:
w = shapefile.Writer('shapefiles/test/polygon')
and your last line should be instead
w.close()
but I get the error 'TypeError: poly() got an unexpected keyword argument 'parts'' - this is just when running the test polygon not using my own data.
I am not sure where I'm going wrong and how I would adapt the code to work for my circles?