Select to view content in your preferred language

How to add Spatial reference to feature service

457
2
11-15-2024 06:18 AM
StuartMoore
Frequent Contributor

How can i add a spatial reference to a feature service?
my feature service is not showing  a spatial reference when querying the extent

StuartMoore_0-1731680091546.png

 

but if i check another feature service it shows one

StuartMoore_1-1731680168202.png

 

i think this is the cause of why my intersection or select by location in pro returns 0 results or just fails 

StuartMoore_2-1731680271421.png

 

 

0 Kudos
2 Replies
TonyAlmeida
MVP Regular Contributor

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"
)

 

 

0 Kudos
StuartMoore
Frequent Contributor

this for some reason the feature layers are all now showing with a wkid and select by location now works...

 

very odd

 

Stu

0 Kudos