Home > arcgis desktop > How do I figure out the length of polyline features in a feature class with a WGS 1984 coordinate system?

How do I figure out the length of polyline features in a feature class with a WGS 1984 coordinate system?

August 26Hits:5
Advertisement

I'm trying to figure out lengths of polyline features in a feature class with a WGS 1984 coordinate system.

Here's code to list lengths:

>>> import arcpy >>> inFc = r"C:\Users\e1b8\Desktop\E1B8\GIS_Stackexchange\data.gdb\test" >>> sr = arcpy.Describe (inFc).spatialReference >>> sr.name u'GCS_WGS_1984' >>> with arcpy.da.SearchCursor (inFc, "SHAPE@") as cursor:     for geom, in cursor:         print geom.length  0.000785568606752 0.000784558202405 0.00117166138222 0.000816779544786 

I'm not sure what units these lengths are in. I know it's generally in the coordinate system's linear units, but WGS 1984 has no linear units.

>>> sr.linearUnitName u'' 

Ultimately I'd like to be able to write code that works with distances and is compatible with both projected and geographic coordinate systems. Usually I use the spatial reference's metersPerUnit property to get to a common unit regardless of the coordinate system's unit, but this throws an error for WGS 1984:

>>> sr.metersPerUnit  Traceback (most recent call last):   File "<pyshell#13>", line 1, in <module>     sr.metersPerUnit AttributeError: SpatialReference: Get attribute metersPerUnit does not exist 

So again, how can I get the length of features? And preferably, how do I figure out their lengths in meters?

Answers

I thought at first the arcpy.Polyline.getLength() method would work, as you can specify a measurement type and units but it did not because it is GCS. As you can see here, we are still in Decimal Degrees:

>>> with arcpy.da.SearchCursor("line_wgs", 'SHAPE@') as rows:
...     for row in rows:
...         print row[0].getLength('PLANAR', 'METERS')
...
0.00193201661559
>>> desc = arcpy.Describe("line_wgs")
>>> desc.spatialReference.factoryCode
4326

What you can do is add a spatial reference to your search cursor (such as the Web Mercator):

>>> with arcpy.da.SearchCursor("line_wgs", 'SHAPE@', spatial_reference=arcpy.SpatialReference(102100)) as rows:
...     for row in rows:
...         print row[0].getLength('PLANAR', 'METERS')
...
215.071313581
>>>

Note, since WGS Web Mercator is in meters you can just use the length property as you did in your first one:

>>> with arcpy.da.SearchCursor("line_wgs", 'SHAPE@', spatial_reference=arcpy.SpatialReference(102100)) as rows:
...     for row in rows:
...         print row[0].length
...
215.071313581
>>>

Related Articles

  • How do I figure out the length of polyline features in a feature class with a WGS 1984 coordinate system?August 26

    I'm trying to figure out lengths of polyline features in a feature class with a WGS 1984 coordinate system. Here's code to list lengths: >>> import arcpy >>> inFc = r"C:\Users\e1b8\Desktop\E1B8\GIS_Stackexchange\data.gdb\test"

  • How to show size/length of sketch while creating new feature?September 5

    While adding a new feature to a feature layer I like to show the size (area)/length of the sketch so that the user has a better feedback while placing the vertexes. So I hook up MapControl's OnMouseMove and get the IEngineEditSketch. But that one onl

  • Finding the length of files and file path of directory structure in a Linux file systemJune 1

    I have a problem on a Linux OS running a version of SMB where if the absolute path to a directory within a Shared Folder is greater than 1024 bytes and the filename component is greater than 256 bytes the SMB service crashes and locks out all other s

  • Metric/parameters to compare length of polylineMarch 10

    What would be a good metric to compare the length of two polylines? A very naive approach would be to define a maximum delta which the two lines can differ. I'm looking for more approaches. For example one that might also take a function over the len

  • How to Calculate length of polyline geometry for several tables in PostGIS?September 6

    PostGIS database contains several geometry (polyline) tables (with names "D1_r", "D2_r", "D3_r"). I calculate length for one "postgis layer" use request: SELECT sum(ST_Length_Spheroid(the_geom,'SPHEROID["WGS 84

  • Cumulative length of polylinesApril 7

    I have a polyline shapefile with streams. I would like to turn this to a raster where there would be a cumulative length sum value in each pixel moving downstream. In other words, this would be an downstream increasing cumulative sum based on polylin

  • Setting unit length in TikZ?April 17

    As I understand it, the basic unit length in TikZ is 1cm, so that for example \draw (0,0) -- (1,0); draws a line 1cm in length. What I want to do is to redefine that length so that all drawings in my document are a different size. Using ConTeXt, how

  • Calculating edge length of polygon within overlapping polygon

    Calculating edge length of polygon within overlapping polygonMarch 3

    I have a layer of wetland polygons and a layer of lakes. I basically want to find the total length of lake shoreline contained within each wetland and add these values as an attribute of the wetlands. This image shows what I'm looking for in red: The

  • ArcGIS coordinate systemMay 9

    I'm developing some software using ArcGIS API, but the question is rather theoretical, as I just came from Google Maps and have no idea where to start; everything seems to be different including the metrics used. I'm not even sure how to explain what

  • Using ArcMap, how may I convert a shapefile to use decimal degrees?

    Using ArcMap, how may I convert a shapefile to use decimal degrees?November 11

    I have a shapefile that currently uses meters as the measure for its coordinate system, but the map framework I wish to use expects decimal degrees. I'd like to reproject my shapefile to use decimal degrees, but I can't seem to figure out how to do s

  • How to extract values from a raster according to Lat and long of the values?January 27

    having 12 files with 12 hdrs for one year: these files are raster (projected WGS84,lat long): samples = 1440 lines = 720 bands = 1 header offset = 0 file type = ENVI Standard data type = 4 interleave = bsq byte order = 0 map info = { Geographic Lat/L

  • Identify what projection this Australian map uses?

    Identify what projection this Australian map uses?August 31

    Im looking to put this map into google maps as custom tiles, but i now learn what projection is and that this map does not use the same format as google's default. You can create custom projections i read in the API. I suspect this map uses a common

  • How to dynamically measure and display radius of circle in OpenLayers?

    How to dynamically measure and display radius of circle in OpenLayers?January 23

    I want to give my user the ability to click on the map and give him a dynamic circle drawing tool which also reads out the radius measurement. That way the user can see how big the circle he creates is. For example, something like this : Any idea how

  • How to create polygon that goes over +/-180 (dateline) in ArcMap?March 31

    I want to create a polygon feature that will go through the dateline (180 long.) in ArcMap. I am using WGS_1984_Web_Mercator_Auxiliary_Sphere (WKID: 3857) for my data frame and my polygonal feature class is defined with the same projected coordinate

  • How do I calculate the distance of a segment of line that is inside a polygon?November 11

    I would like to calculate the distance of a portion of a line that is inside a polygon, as well as the portion that is outside of the polygon, based on from/to lat/long points on the line, and the lat/long points that define the polygon boundary. Use

  • Import Google Maps locations to ArcMapDecember 14

    I have a problem with importing a list of coordinates to ArcMap. I have a shape file of regions of Chile and I would like to add a list of locations with coordinates I got from Google Maps. The shape file with the Chilean regions is coming from http:

  • how to export perimeter of a drawline tool to textbox arcobjects?April 19

    I had a custom drawing tool which is available in samples of arcGIS 10.1 Sdk for .Net. When we draw a line or any perimeter on the map, and right click on the line and go to properties, it display a line length. EDITED: I want to send that line lengt

  • ArcMap 3D profile graph gives a level lineJuly 1

    ArcMap's Profile Graph in 3D analyst works great for drawing a line on the map and seeing the profile. I am doing this part easily; single segments, multiple segments it works fine. However, it is not working for me with existing features. I follow d

  • How can I draw texts within a cartesian coordinate system with TikZ?

    How can I draw texts within a cartesian coordinate system with TikZ?August 16

    I am new to TikZ and was wondering how to draw a simple figure as given below. --------------Solutions------------- You could use pgfplots for drawing coordinate system with grid, axis and ticks with labels, without drawing any plot place the text as

  • What is the minimum ethernet cable length for a CAT6 gigabit connection?February 1

    We run a Netgear GS724Tv3 switch and part of the configuration per port is an option for "Lower Power Mode". The documentation for the switch lists this feature as a "Green Ethernet Configuration" feature: A cable test is performed whe

Copyright (C) 2017 ceus-now.com, All Rights Reserved. webmaster#ceus-now.com 14 q. 0.917 s.