I can't save featuresets to shapefiles, convert between shapely arcgis polygon, calculate area, get enrichment data...
def save_polygon_to_shapefile( self, polygon: Polygon, polygon_type: str, filename: str ) -> tuple[pathlib.Path, str]: """Saves a arcgis.geometry.polygon to a shapefile as a Feature Set. Args: polygon (Polygon): an arcgis.geometry.polygon object polygon_type (str): a string representing the type of polygon as defined in the config file filename (str): a string representing the name of the file to save. Returns: tuple[pathlib.Path, str]: a tuple containing a patlib.path to the file directory and the filename """ file_dir, filename = self.generate_polygon_file_path( polygon_type=polygon_type, filename=filename ) f = Feature(geometry=polygon, attributes={}) fset = FeatureSet([f]) try: """ Note: Arcgis featureset.save splits by . from the right and takes the first part as the file name, so we must make sure to add a decimal after the filename if the unit in the polygon type has a decimal point but the actual extension (shp) added here doesnt actually matter its just for readability. """ fset.save(save_location=file_dir, out_name=f"{filename}.shp") except Exception as e: self.logger.warning(e, exc_info=True) return None, None return file_dir, filename
How do I save a feature set to a shapefile without depending on Arcgis Pro?
If this class is not dependent on Arcpy, you can create a new environment or start a new virtual environment based off of a python installation and use `pip install arcgis` and whatever other modules the class or script depends on.
If they workflow does depend on Arcpy, you will need to find an alternative library to use in the workflows, otherwise you will have to use a ArcPro python environment.
I am using arcgis. I have never used ArcPy.
Have you tried GeoPandas?
https://geopandas.org/en/stable/docs/user_guide/io.html#writing-spatial-data
I am trying it right now. I am just not familiar enough with the formats to be sure if their shapefiles are compatible with ArcGIS or not. Since ArcGIS outputs 5 files instead of just 1.
A Shapefile will always have a minimum of 3 files the .shp, .dbf, and .shx. Plus a .prj for projecting to real world coordinates in a GIS. You can most definitely use a Shapefile that has been generated by GeoPandas in ArcGIS.
The arcgis library is not dependent on Arc Pro, the underlying environment you are running the script in is what is dependent on Arc Pro. If you are using the prepackages arcgispro-py3 environment or any clone of that environment to run your script, you always get that error until you sign in to ArcGIS Pro with a active user account.
The way around this is to install python separately, or another instance of a package manager like Anaconda that is not linked to ArcGIS Pro at all.
I installed python myself and I am using a conda environment I built from the the one supplied by Arcgis so that must be the issue. The license error only occurs with certain functions even when I provide my own GIS with a working API Key. The rest of the functions don't trigger it.
I have checked my conda environment and will remove arcpy and arcgispro and test again.
Could you happend to let me know the minimal conda environment yaml file to use the arcgis library without running into this issue? Do I just need to remove arcpy and arcgispro? If I try to remove them conda fails to resolve the package.
When I try to install ArcGIS fresh on a new Conda environment, it says it will install arcgispro. So this indicates arcgispro is in fact a dependency for arcgis.
(DS) PS ...> conda install arcgis
Channels:
- esri
- defaults
- conda-forge
Platform: win-64
Collecting package metadata (repodata.json): done
Solving environment: done
## Package Plan ##
environment location: ...\AppData\Local\anaconda3\envs\DS
added / updated specs:
- arcgis
The following packages will be downloaded:
package | build
---------------------------|-----------------
annotated-types-0.6.0 | py_2 15 KB esri
arcgis-2.4.1.3 | py312_152 7.1 MB esri
arcgispro-3.5 | 0 3 KB esri
....
When I call arcgis through pip or through `conda install -c esri arcgis` I do not get the arcgispro-3.5 package anywhere in the plan or build or upon install. What versions of things are you running?