1

I am trying to convert stream segments to text. This is function for the script

#function to convert feature to text as ungenerate command in ArcGIS workstation

def featureTotext(path,feature,TextFileName):

import string, os, sys, locale, arcgisscripting
gp = arcgisscripting.create()
gp.overwriteoutput = 1
msgNotEnoughParams = "Incorrect number of input parameters."
msgUseValidDecimalPointSep = "Please use one of the valid decimal point separators."
try:
    os.chdir(path)
    inputFC = feature
    outFile = open(TextFileName, "w")
    sepchar=""
    inDesc = gp.describe(inputFC)
    inRows = gp.searchcursor(inputFC)
    inRow = inRows.next()
   # outFile.write(inDesc.ShapeType + "\n")

    while inRow:
        feat = inRow.GetValue(inDesc.ShapeFieldName)

        partnum = 0
        partcount = feat.partcount

        while partnum < partcount:
            outFile.write("\t"+str(inRow.GetValue('GRID_CODE')) + "\n")
            print inRow.GetValue('GRID_CODE')
            part = feat.getpart(partnum)
            part.reset()
            pnt = part.next()
            pnt_count = 0
            while pnt:
                outLine = "\t" + str(pnt.x) + "\t" + str(pnt.y) + "\n"
                if sepchar == "": outFile.write(outLine)
                else: outFile.write(outLine.replace(".", sepchar))
                pnt = part.next()
                pnt_count += 1
                if not pnt:
                    pnt = part.next()
                    if pnt:
                        outFile.write("InteriorRing\n")

            partnum += 1
            outFile.write("END\n")
        inRow = inRows.next()
    outFile.write("END")
    outFile.flush()
    outFile.close()
    print outFile

except Exception, ErrorDesc:
    gp.AddError(ErrorDesc[0])
    if outFile: outFile.close()
    gp.AddError(gp.getmessages(2))

This script gives output similar as the "ungenerate" command in ArcGIS workstation. When used, this function gives the fewer output points than using the ungenerate command.

Output from this function look like :
1354
391367.254831   9456327.37568
389617.254831   9458077.37568
389617.254831   9459077.37568
388117.254831   9460577.37568
387117.254831   9460577.37568
380117.254831   9467577.37568

END

I want to have more points (smaller interval) while extracting X and Y coordinates from a feature. How can I do this ?

4
  • If you are trying to create the same output as Arc: UNGENERATE, then did you try the suggestion at gis.stackexchange.com/a/7344/115 ?
    – PolyGeo
    Oct 14, 2014 at 5:41
  • Yes I already tried with that. I want to know about extracting X Y coordinates at finer scale
    – Ja Geo
    Oct 14, 2014 at 5:59
  • Asking for coordinates at "finer scale" doesn't make much sense -- UNGENERATE did not do on-the-fly densification. And your logic for handling multiple parts is flawed (not that stream segments are likely to be multi-part).
    – Vince
    Oct 14, 2014 at 13:08
  • is the version tag correct? arc 10.1 - using arcgisscripting? Oct 14, 2014 at 13:40

3 Answers 3

1

The script will return an array of point objects for each part (returned by the GetPart method) for each record in the feature class. The number of points returned is not defined by any tolerance; the array will contain all the vertices that make up that polygon part.

The only way to get more points would be to place them on the existing lines, which (if I'm understanding the your requirement correctly) would be redundant.

"http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//002z0000001t000000"

"http://help.arcgis.com/en/sdk/10.0/arcobjects_net/componenthelp/index.html#/IGpDescribeGeometry_Interface/002n000001nw000000/"

1

I want to have more points (smaller interval) while extracting X and Y coordinates from a feature. How can I do this ?

If you have access to Standard or Advanced license levels, run Densify (arcpy.Densify_edit) on the lines before converting to text. Be aware that this can change the shape of the geometry especially along curves, though individual vertices should remain on the original line's path.

0

I do not know how this will be done by script, but if you have a vector data and want it in a text file or in excel format then:

  1. Add layer in ArcMap
  2. Open attribute table
  3. Select all the features and from right click you select copy features and paste them in excel or word file.
2
  • Thank you for your suggestion, but I don't want the output in excel or word file format. I want to generate the same output as ungenerate command in ArcGIS Workstation
    – Ja Geo
    Oct 14, 2014 at 4:58
  • @Singh If you are interested in the outcome of this Q&A then you should Favorite it by clicking the icon beneath the up/down vote counter next to the question.
    – PolyGeo
    Oct 14, 2014 at 5:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.