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

  • SEARCH
  • Home
  • 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 8741163
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T11:15:41+00:00 2026-06-13T11:15:41+00:00

I wrote this function to read Las file and save a shapefile. The function

  • 0

I wrote this function to read Las file and save a shapefile. The function creates a shapefile with 8 fields. What i wish insert a parse element in the function in order to select the fields i wish to save LAS2SHP(inFile,outFile=None,parse=None). if None all fields are saved. if parse is
parse=”irn” the fields intensity, return_number, and number_of_returns are saved. following the legend

"i": p.intensity,
"r": p.return_number,
"n": p.number_of_returns,
"s": p.scan_direction,
"e": p.flightline_edge,
"c": p.classification,
"a": p.scan_angle, 

I wrote a solution if….ifelse….else really code consuming (and not elegant). Thanks for all helps and suggestions for saving code

thanks in advance
Gianni

here the original function in python

import shapefile
from liblas import file as lasfile

def LAS2SHP(inFile,outFile=None):
    w = shapefile.Writer(shapefile.POINT)
    w.field('Z','C','10')
    w.field('Intensity','C','10')
    w.field('Return','C','10')
    w.field('NumberRet','C','10')
    w.field('ScanDir','C','10')
    w.field('FlightEdge','C','10')
    w.field('Class','C','10')
    w.field('ScanAngle','C','10')
    for p in lasfile.File(inFile,None,'r'):
        w.point(p.x,p.y)
        w.record(float(p.z),float(p.intensity),float(p.return_number),float(p.number_of_returns),float(p.scan_direction),float(p.flightline_edge),float(p.classification),float(p.scan_angle))
    if outFile == None:
        inFile_path, inFile_name_ext = os.path.split(os.path.abspath(inFile))
        inFile_name = os.path.splitext(inFile_name_ext)[0]
        w.save("{0}\\{1}.shp".format(inFile_path,inFile_name))
    else:
        w.save(outFile)
  • 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-13T11:15:42+00:00Added an answer on June 13, 2026 at 11:15 am

    Perhaps try something like this:

        pdata = [p.z] + [getattr(p, pattr[key]) for key in parse]
        pdata = map(float, pdata)
        w.record(*pdata)
    
    • for key in parse loops through the letters in parse. For example,
      if parse = 'irn' then key loops through the values i, r, n.
    • pattr is a dict. pattr[key] is the name of the associated
      attribute. For example, pattr['i'] is "intensity".
    • getattr(p, pattr[key]) is the value of the pattr[key] attribute
      in p. For example, getattr(p, "intensity") is p.intensity. It is the way to get attribute values when you know the name of the attribute as a string, (e.g. pattr[key]).
      The * in w.record(*pdata) unpacks pdata before sending the arguments on to w.record. For example, w.record(*[1,2,3]) is equivalent to w.record(1,2,3). It is the way one sends an arbitrary number of arguments to a function.

    For example,

    import shapefile
    from liblas import file as lasfile
    
    pattr = {
        "i": 'intensity',
        "r": 'return_number',
        "n": 'number_of_returns',
        "s": 'scan_direction',
        "e": 'flightline_edge',
        "c": 'classification',
        "a": 'scan_angle',
        }
    
    wattr = {
        "i": 'Intensity',
        "r": 'Return',
        "n": 'NumberRet',
        "s": 'ScanDir',
        "e": 'FlightEdge',
        "c": 'Class',
        "a": 'ScanAngle',
        }
    
    def LAS2SHP(inFile, outFile=None, parse = 'irnseca'):
        w = shapefile.Writer(shapefile.POINT)
        w.field('Z','C','10')
        for key in parse:
            w.field(wattr[key],'C','10')
        for p in lasfile.File(inFile,None,'r'):
            w.point(p.x,p.y)
            pdata = [p.z] + [getattr(p, pattr[key]) for key in parse]
            pdata = map(float, pdata)
            w.record(*pdata)       
        if outFile == None:
            inFile_path, inFile_name_ext = os.path.split(os.path.abspath(inFile))
            inFile_name = os.path.splitext(inFile_name_ext)[0]
            w.save("{0}\\{1}.shp".format(inFile_path,inFile_name))
        else:
            w.save(outFile)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I write this function, but what's its return value. (defn read-data [file] (let [code
I wrote a code to read *.las file in Python. *las file are special
I just wrote this function to read a series of email addresses from a
I wrote this function to make columns sortable. I want to rearrange divs based
I wrote this function for filling closed loop, pixvali is declared globally to store
I wrote this function to get the unread count of google reader items. function
I wrote this function to get a pseudo random float between 0 .. 1
I wrote this function to communicate with an external program. Such program takes input
So I wrote this function that is given possible numbers, and it has to
I wrote this little function to fill a drop down list with data from

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.