POST
|
Hello, We used the b version, the same as the GWmodel R package for AICc calculation in our GWR implementation. Thanks.
... View more
08-11-2022
01:51 PM
|
0
|
1
|
756
|
POST
|
Hi Chi, The polygon geometries were not correctly created in your script. If you print the polygons as WKT, you will find the first one is empty (I deleted the inserting actions here): import arcpy
import arcpy
# Define Ticket
class Ticket(object):
id = 0
coordinates = ""
cleanCoordinates = []
def __init__(self, id):
self.id = id
# Sample tickets
ticket1 = Ticket(30190000001)
ticket1.coordinates = "39.938690/-75.153437,39.938634/-75.152868,39.936101/-75.153427,39.936228/-75.153883"
ticket1.cleanCoordinates = [c.split("/") for c in ticket1.coordinates.split(",")]
ticket2 = Ticket(30190000002)
ticket2.coordinates = "40.013851/-75.200242,40.015240/-75.198461,40.017056/-75.201218,40.015774/-75.203267,40.015158/-75.204930"
ticket2.cleanCoordinates = [c.split("/") for c in ticket2.coordinates.split(",")]
resultsPolygon = [ticket1, ticket2]
for j in resultsPolygon:
print("Polygon: " + str(j.id))
array = arcpy.Array()
for coords in j.cleanCoordinates:
pointObject = arcpy.Point()
pointObject.X = float(coords[1])
pointObject.Y = float(coords[0])
array.add(pointObject)
polygonObject = arcpy.Polygon(array)
print(polygonObject.WKT)
print("Finished.")
"""
Polygon: 30190000001
MULTIPOLYGON EMPTY
Polygon: 30190000002
MULTIPOLYGON (((-75.19927978515625 40.01470947265625, -75.201171875 40.01708984375, -75.20379638671875 40.01507568359375, -75.19927978515625 40.01470947265625)))
Finished.
""" Adding the spatial reference when creating the polygon will solve this issue. since the projection is WGS 1984, the spatial reference code is 4326. # Define Ticket
class Ticket(object):
id = 0
coordinates = ""
cleanCoordinates = []
def __init__(self, id):
self.id = id
# Sample tickets
ticket1 = Ticket(30190000001)
ticket1.coordinates = "39.938690/-75.153437,39.938634/-75.152868,39.936101/-75.153427,39.936228/-75.153883"
ticket1.cleanCoordinates = [c.split("/") for c in ticket1.coordinates.split(",")]
ticket2 = Ticket(30190000002)
ticket2.coordinates = "40.013851/-75.200242,40.015240/-75.198461,40.017056/-75.201218,40.015774/-75.203267,40.015158/-75.204930"
ticket2.cleanCoordinates = [c.split("/") for c in ticket2.coordinates.split(",")]
resultsPolygon = [ticket1, ticket2]
spatial_reference = arcpy.SpatialReference(4326)
for j in resultsPolygon:
print("Polygon: " + str(j.id))
array = arcpy.Array()
for coords in j.cleanCoordinates:
pointObject = arcpy.Point()
pointObject.X = float(coords[1])
pointObject.Y = float(coords[0])
array.add(pointObject)
polygonObject = arcpy.Polygon(array, spatial_reference)
print(polygonObject.WKT)
print("Finished.")
"""
Polygon: 30190000001
MULTIPOLYGON (((-75.15343699999994 39.938690000000065, -75.153882999999951 39.936228000000028, -75.153426999999965 39.936101000000065, -75.152867999999955 39.938634000000036, -75.15343699999994 39.938690000000065)))
Polygon: 30190000002
MULTIPOLYGON (((-75.200241999999946 40.013851000000045, -75.198460999999952 40.015240000000063, -75.201217999999983 40.017056000000025, -75.203266999999983 40.015774000000079, -75.204929999999933 40.015158000000042, -75.200241999999946 40.013851000000045)))
Finished.
"""
... View more
01-31-2019
05:45 PM
|
2
|
2
|
684
|
Title | Kudos | Posted |
---|---|---|
2 | 01-31-2019 05:45 PM |
Online Status |
Offline
|
Date Last Visited |
03-13-2024
03:23 PM
|