Question: import shapefile , , def collect _ points ( ) : , points = [ ] , while
"import shapefile
"def collectpoints:
points
while True:
lat floatinputEnter latitude :
lon floatinputEnter longitude :
points.appendlon lat
morepoints inputDo you want to add another point? yesno: striplower
if morepoints 'yes':
printFinished entering points.
break
return points
"def savepointstoshapefilepoints filename'points.shp:
with shapefile.Writerfilename shapeTypeshape.POINT as shp:
shpfieldIDN
for ilat lon in enumeratepoints:
shppointlon lat
shprecordi
"def readpointsfromshapefilefilename 'point.shp:
with shapefile.Readerfilename as shp:
for shapeRecord in shpinterShaperRecords:
printfID: shapeRecordrecord Latitude: shapepoints Longitude: shapeRecordshape.points
"def main:
points collectpoints
if points:
savepointstoshapefilepoints
printPoints save to shapefile.
printReading points from shapefile:
readpointsfromshapefile
else:
printNo points to save.
if namemain:
main
Help solve the attached file, run the script, input prompt for latitude and longitude inputs in pyton demo, : Make sure you are adding multiple points. Right now, the code breaks after one entry, so if you want to add more, you need to allow for that by asking if you'd like to input more points.
Doublecheck that your function is saving the points correctly to the shapefile. Specifically, ensure the shapefile is writing each point and its corresponding ID
When opening the shapefile, use GIS software like QGIS or ArcGIS rather than a text editor, as the file format is binary and can't be read directly.
Ensure that the dbf file has a field defined for storing the point IDs, which might be why it appears empty.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
