How can i add a spatial reference to a feature service?
my feature service is not showing a spatial reference when querying the extent
but if i check another feature service it shows one
i think this is the cause of why my intersection or select by location in pro returns 0 results or just fails
I believe you would have to overwrite the service. Try this,
import arcpy
# Your portal connection
arcpy.SignInToPortal("https://www.yourportal.com", "your_username", "your_password")
# URL to the feature service
feature_service_url = "https://services.yourportal.com/your_org/arcgis/rest/services/your_service/FeatureServer/0"
# output location
local_feature_class = r"C:\workspace_path\temp_feature_class.gdb\your_feature_class"
# Define the desired spatial reference spatial reference
desired_spatial_ref = arcpy.SpatialReference(4326) # WGS 1984
Download the feature service soyou can update
arcpy.FeatureClassToFeatureClass_conversion(
in_features=feature_service_url,
out_path="C:\\workspace_path\\temp_feature_class.gdb",
out_name="your_feature_class"
)
Update spatial reference
arcpy.DefineProjection_management(local_feature_class, desired_spatial_ref)
Overwrite the feature service
arcpy.UploadServiceDefinition_management(
in_sd_file=r"C:\path_to_your_service_definition.sd",
in_server="My Hosted Services",
in_portal_folder="TargetFolder"
)
this for some reason the feature layers are all now showing with a wkid and select by location now works...
very odd
Stu