Select to view content in your preferred language

'NoneType' object has no atribute for arcpy.PointGeometry

1025
3
09-20-2023 04:22 PM
Labels (3)
PabloParra
Emerging Contributor

Hello! I'm wrapping up my coordenates converter but when I go and run it in ArcGis Pro it got the error down below. I've checked PATH (both) and checked the intalation of the app itself. If you know how to fix it please don't hesitate to reply!

Thanks in advance.

PD: I'll also post the code

import arcpy

arcpy.env.workspace = r"C:\Users\Usuario\Desktop\DocsUSACH\SIG_TAREA1"
print('Welcome to the coordinates converter, where you can convert to and from UTM-Geographics, all within the WGS84 Datum and between the 18S-19S UTM zone')

# Toma de Datos
formato = input('Please choose the input coords to convert, either being (G)eographic or (U)TM, please remember the geographic coords HAS to be in the WGS84 Datum: ')

formato = formato.lower()

if formato == 'g':
    print('Please remember that if you input the coordinates in degrees it may not be as precise as the asked format')

    # RECOLECCION DE DATOS
    long_input = input('Enter the longitude in a numeric format (not in degrees) and with dot (.) not comma (,): ')
    lat_input = input('Enter the latitude in a numeric format (not in degrees) and with dot (.) not comma (,): ')
    long_input = long_input.replace(',', '.').replace('°', '')
    lat_input = lat_input.replace(',', '.').replace('°', '')

    try:  # BLOQUE TRY PARA PROBLEMAS DE FORMATO POR USUARIO
        long = float(long_input)
        lat = float(lat_input)

        # Crear punto y geometría en ArcGIS con coordenadas Geográficas
        punto_entrante = arcpy.Point(long, lat)
        geometria_entrante = arcpy.PointGeometry(punto_entrante, arcpy.SpatialReference(4326))  # 4326 es el código para WGS84

        # Convertir coordenadas geográficas a UTM
        huso = int((long + 180) / 6) + 1

        if huso == 18:
            punto = arcpy.Point(long, lat)
            hemisferio = 'S'
            utm_sr = arcpy.SpatialReference(32718)  # CODIGO SRID PARA HUSO 18
            point_geometry = arcpy.PointGeometry(punto, utm_sr)

        elif huso == 19:
            punto = arcpy.Point(long, lat)
            hemisferio = 'S'
            utm_sr = arcpy.SpatialReference(32719)  # CODIGO SRID PARA HUSO 19
            point_geometry = arcpy.PointGeometry(punto, utm_sr)
        else:
            print('Invalid coordinates, please try again with coords within the 18S and 19S.')
            exit()

        utm_sistref = arcpy.SpatialReference(32611)  # Código para UTM

        geometria_salida = geometria_entrante.projectAs(utm_sistref)

        if geometria_salida is not None:
            este_utm = geometria_salida.firstPoint.X
            norte_utm = geometria_salida.firstPoint.Y

            # Mostrar las coordenadas UTM
            print('UTM East', este_utm)
            print('UTM North', norte_utm)
            print('Zone', str(huso) + 'S')
        else:
            print('Failed to project coordinates to UTM. Please check the input coordinates.')

    except ValueError:
        print('Invalid input. Please enter numeric coordinates')

# Inicio Segunda opción
elif formato == 'u':
    print('Please remember that if you input the coordinates in degrees it may not be as precise as the asked format')

    # Recolección de Datos
    utm_y_input = input('Enter the northing of the coordinate in a numeric format, no degrees: ')
    utm_x_input = input('Enter the easting of the coordinate in a numeric format, no degrees: ')
    utm_zone = int(input('Enter the UTM zone corresponding to the coordinates, only between (18)S or (19)S: '))

    utm_y_input = utm_y_input.replace(',', '.').replace('°', '')
    utm_x_input = utm_x_input.replace(',', '.').replace('°', '')

    try:
        utm_y = float(utm_y_input)
        utm_x = float(utm_x_input)

        # Determinación código de transformación
        utm_codigo = int(32600 + utm_zone)

        # Crear objeto Point usando UTM y su código correspondiente
        utm_point = arcpy.Point(utm_x, utm_y, None, None, None, utm_codigo)

        # Definir sistema de referencia (Spatial Reference) para WGS85 y realizar conversión
        sr_wgs84 = arcpy.SpatialReference(4326)

        geografic_point = utm_point.projectAs(sr_wgs84)

        geo_x = geografic_point.X
        geo_y = geografic_point.Y

        # Devolver resultados
        print('Your new coordinates in the WGS84 Datum are:', 'X=', geo_x, 'Y=', geo_y)

    except ValueError:
        print('Invalid input. Please enter numeric coordinates.')

else:
    print('Invalid input format. Please choose (G)eographic or (U)TM: ')
0 Kudos
3 Replies
DanPatterson
MVP Esteemed Contributor

Before I read any further, you have converted a python data type (aka, long)

Replace references to 'long' beginning on line 21 with

 

lng_ = float(long_input)

 


... sort of retired...
PabloParra
Emerging Contributor

Done! But not solved it sadly, why is it necessary to change the variable name? Thanks for the Reply!

Also, do you recomend any python editor for windows?. 

I look forward to your response!

import arcpy

arcpy.env.workspace = r"C:\Users\Usuario\Desktop\DocsUSACH\SIG_TAREA1"
print('Welcome to the coordinates converter, where you can convert to and from UTM-Geographics, all within the WGS84 Datum and between the 18S-19S UTM zone')

# Toma de Datos
formato = input('Please choose the input coords to convert, either being (G)eographic or (U)TM, please remember the geographic coords HAS to be in the WGS84 Datum: ')

formato = formato.lower()

if formato == 'g':
    print('Please remember that if you input the coordinates in degrees it may not be as precise as the asked format')

    # RECOLECCION DE DATOS
    long_input = input('Enter the longitude in a numeric format (not in degrees) and with dot (.) not comma (,): ')
    lat_input = input('Enter the latitude in a numeric format (not in degrees) and with dot (.) not comma (,): ')
    
    lng_input = lng_input.replace(',', '.').replace('°', '')
    lat_input = lat_input.replace(',', '.').replace('°', '')

    try:  # BLOQUE TRY PARA PROBLEMAS DE FORMATO POR USUARIO
        lng_ = float(long_input)
        lat = float(lat_input)

        # Crear punto y geometría en ArcGIS con coordenadas Geográficas
        punto_entrante = arcpy.Point(lng_, lat)
        geometria_entrante = arcpy.PointGeometry(punto_entrante, arcpy.SpatialReference(4326))  # 4326 es el código para WGS84

        # Convertir coordenadas geográficas a UTM
        huso = int((lng_ + 180) / 6) + 1

        if huso == 18:
            punto = arcpy.Point(lng_, lat)
            hemisferio = 'S'
            utm_sr = arcpy.SpatialReference(32718)  # CODIGO SRID PARA HUSO 18
            point_geometry = arcpy.PointGeometry(punto, utm_sr)

        elif huso == 19:
            punto = arcpy.Point(lng_, lat)
            hemisferio = 'S'
            utm_sr = arcpy.SpatialReference(32719)  # CODIGO SRID PARA HUSO 19
            point_geometry = arcpy.PointGeometry(punto, utm_sr)
        else:
            print('Invalid coordinates, please try again with coords within the 18S and 19S.')
            exit()

        utm_sistref = arcpy.SpatialReference(32611)  # Código para UTM

        geometria_salida = geometria_entrante.projectAs(utm_sistref)

        if geometria_salida is not None:
            este_utm = geometria_salida.firstPoint.X
            norte_utm = geometria_salida.firstPoint.Y

            # Mostrar las coordenadas UTM
            print('UTM East', este_utm)
            print('UTM North', norte_utm)
            print('Zone', str(huso) + 'S')
        else:
            print('Failed to project coordinates to UTM. Please check the input coordinates.')

    except ValueError:
        print('Invalid input. Please enter numeric coordinates')

# Inicio Segunda opción
elif formato == 'u':
    print('Please remember that if you input the coordinates in degrees it may not be as precise as the asked format')

    # Recolección de Datos
    utm_y_input = input('Enter the northing of the coordinate in a numeric format, no degrees: ')
    utm_x_input = input('Enter the easting of the coordinate in a numeric format, no degrees: ')
    utm_zone = int(input('Enter the UTM zone corresponding to the coordinates, only between (18)S or (19)S: '))

    utm_y_input = utm_y_input.replace(',', '.').replace('°', '')
    utm_x_input = utm_x_input.replace(',', '.').replace('°', '')

    try:
        utm_y = float(utm_y_input)
        utm_x = float(utm_x_input)

        # Determinación código de transformación
        utm_codigo = int(32600 + utm_zone)

        # Crear objeto Point usando UTM y su código correspondiente
        utm_point = arcpy.Point(utm_x, utm_y, None, None, None, utm_codigo)

        # Definir sistema de referencia (Spatial Reference) para WGS85 y realizar conversión
        sr_wgs84 = arcpy.SpatialReference(4326)

        geografic_point = utm_point.projectAs(sr_wgs84)

        geo_x = geografic_point.X
        geo_y = geografic_point.Y

        # Devolver resultados
        print('Your new coordinates in the WGS84 Datum are:', 'X=', geo_x, 'Y=', geo_y)

    except ValueError:
        print('Invalid input. Please enter numeric coordinates.')

else:
    print('Invalid input format. Please choose (G)eographic or (U)TM: ')

Thanks!

0 Kudos
BlakeTerhune
MVP Regular Contributor

@PabloParra wrote:

why is it necessary to change the variable name?


The idea is to avoid reserved keywords the language uses for normal interpretation of the code. Although I don't see "long" as being one of them, it certainly sounds like a keyword so it's better to avoid it.

As for the error, "'NoneType' object has no atribute for arcpy.PointGeometry" is saying that somewhere you're calling arcpy.PointGeometry with a variable that has a value of None (null). Look at the line it errors and inspect the variables you're using. I suspect one of them is null.

0 Kudos