Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8851955
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T13:17:00+00:00 2026-06-14T13:17:00+00:00

I would like to generate a .shp with five points using shapefile available through

  • 0

I would like to generate a .shp with five points using shapefile available through pyshp. However, when I loop through my list I get only the last value. This makes sense as I did not append any of the points to an empty list (e.g. new_shp = [])

import shapefile as sf
import os

filename2 = 'test/point10'
lis = [(33.21, -122.15, 'france'), (35.31, -122.15, 'germany'), (35.41, -123.15, 'Hawaii'), (30.51, -122.15, 'Philippines'),(32.30, -122.15, 'Texas')]
for l in lis:
    w = sf.Writer(sf.POINT)
    w.point(l[0], l[1])
    w.field('location')
    w.record(l[2], 'Point')
    w.save(filename2)

# create the PRJ file
prj = open("%s.prj" % filename2, "w")
epsg = 'GEOGCS["WGS 84",DATUM["WGS_1984",SPHEROID["WGS 84",6378137,298.257223563]],PRIMEM["Greenwich",0],UNIT["degree",0.0174532925199433]]'
prj.write(epsg)
prj.close()

I am assumming that I have to append all the points somewhere in the for loop, but I don’t understand how to actually append it. How do I effectively loop through lis to get a .shp file with all five points?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T13:17:01+00:00Added an answer on June 14, 2026 at 1:17 pm

    To append to the save file I simply had to rearrange some terms. There is no empty append list that needs to be made.

    import shapefile as sf
    import os
    
    filename2 = 'test/point16'
    
    lis = [(33.21, -122.15, 'france'), (35.31, -122.15, 'germany'), (35.41, -123.15, 'Hawaii'), (30.51, -122.15, 'Philippines'),(32.30, -122.15, 'Texas')]
    
    w = sf.Writer(sf.POINT)
    w.field('location')
    
    for l in lis:
        w.point(l[0], l[1])
        w.record(l[2], 'Point')
    w.save(filename2)
    
    # create the PRJ file
    prj = open("%s.prj" % filename2, "w")
    epsg = 'GEOGCS["WGS 84",DATUM["WGS_1984",SPHEROID["WGS 84",6378137,298.257223563]],PRIMEM["Greenwich",0],UNIT["degree",0.0174532925199433]]'
    prj.write(epsg)
    prj.close()
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to generate a list of all the files that have been
I would like to generate random points on a 3D box defined by its
I would like to generate funnel chart on my web page. I am using
I would like to generate flow chart from a list of steps. For example
I would like generate list like day=>title: $news = $this->News->find('list', array( 'conditions' => array(
I would like to generate a list of URLs for a domain but I
I would like to generate random points on a 2D surface, distributed around a
I would like to generate C wrappers over some C++ API using SWIG. From
I would like to generate coupon codes , e.g. AYB4ZZ2 . However, I would
I would like to generate a SQLFORM with radiobuttons using the radiobutton widget as

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.