enzococca / Survey123ToLayer

This application provides a graphical user interface (GUI) for converting data from a SQLite database into GeoPackage and Shapefile formats, with optional filtering by keywords. It is built using PyQt5 and integrates with geospatial libraries to handle the conversion process.
GNU General Public License v3.0
0 stars 0 forks source link

Error when using the code with polygon survey #1

Open Eslam-mohakim opened 4 months ago

Eslam-mohakim commented 4 months ago

when trying to use the same code df["geometry"] = df["area"].apply(create_geometry) but for area for Polygon type, it fires this error: "ValueError: setting an array element with a sequence. The requested array has an inhomogeneous shape after 1 dimensions. The detected shape was (25,) + inhomogeneous part."

this is the function: def create_geometry(x): if x == x and isinstance(x, dict) and "rings" in x and isinstance(x["rings"], list) and len(x["rings"]) > 0: return Polygon(coordinates) else: return np.nan

enzococca commented 4 months ago

The error message setting an array element with a sequence is generally an indication that you're trying to set an array (or in this case, a column in a DataFrame) with a list or a sequence of values when it's expecting only a single value.

A possible problem may be that Polygon(coordinates) is returning a sequence (or list) of values instead of a single value and hence the error. Also, you might want to check that each dict your function checks contains rings that themselves do not contain lists that are sequences. try this:

def create_geometry(x): if x == x and isinstance(x, dict) and "rings" in x and isinstance(x["rings"], list) and len(x["rings"]) > 0:

assuming that "rings" is a nested list where each sub-list

is a coordinate pair coordinates = [tuple(i) for i in x["rings"]]

    print(coordinates)# look if the coordinates is neasted list
    return Polygon(coordinates)
else:
    return np.nan

don't forget to import numpy

impoert numpy as np

Il giorno mar 23 apr 2024 alle ore 09:54 Eslam-mohakim < @.***> ha scritto:

when trying to use the same code df["geometry"] = df["area"].apply(create_geometry) but for area for Polygon type, it fires this error: "ValueError: setting an array element with a sequence. The requested array has an inhomogeneous shape after 1 dimensions. The detected shape was (25,)

  • inhomogeneous part."

this is the function: def create_geometry(x): if x == x and isinstance(x, dict) and "rings" in x and isinstance(x["rings"], list) and len(x["rings"]) > 0: return Polygon(coordinates) else: return np.nan

— Reply to this email directly, view it on GitHub https://github.com/enzococca/Survey123ToLayer/issues/1, or unsubscribe https://github.com/notifications/unsubscribe-auth/AA2P5KEJPPBFB6TSO6RARKLY6YHUDAVCNFSM6AAAAABGUKXMZSVHI2DSMVQWIX3LMV43ASLTON2WKOZSGI2TQMRQGU2DAMI . You are receiving this because you are subscribed to this thread.Message ID: @.***>

-- Enzo Cocca PhD in "Science and Technology for Archaeology and Cultural Heritage"

ISMEO International Association of Mediterranean and Oriental Studies

mail: @.*** cell: +393495087014

enzococca commented 4 months ago

Furthermore, you should then apply the create_geometry function instead of:

df["geometry"] = df["location"].apply( lambda x: Polygon(x["rings"][0]) ) in

df["geometry"] = df["area"].apply(create_geometry) )