I have a GeoPackage with a vector layer in it. The layer is in WGS84 projection and it has several features.
When I add the layer to the active map using ArcCatalog, the layer displays correctly and the layer has the correct extent envelope displayed in the layer properties. I can right click on the layer and choose "zoom to extent" and ArcPro does indeed zoom to the layer.
But when I add the layer to the map using the following C# code the layer gets added to the map and displays OK, but the extent defaults to the maximum range of WGS84 (-180, 90, 180, -90).
uri = new Uri("file:///C:/mydata/mygeopackage.gpkg/main.vwReaches")
Layer layer = LayerFactory.Instance.CreateLayer(uri, parent as ILayerContainerEdit, 0, "my layer");
When I right click on the layer and choose "zoom to extent" ArcPro blinks and shifts slightly, but does not zoom to the correct extent.
Both methods produce identical layers in ArcGIS Pro. They possess the same SQL query. The only difference is that the layer added from code has the default WGS84 extent.
Any ideas please?
Solved! Go to Solution.
I finally solved this by making a connection to the GeoPackage first. Then using this connection to create the layer. I suspect that this avoids ArcPro making assumptions about the uri.
CIMStandardDataConnection conn = new CIMStandardDataConnection();
conn.WorkspaceConnectionString = string.Format(@"DATABASE=C:/mydata/mygeopackage.gpkg");
conn.WorkspaceFactory = WorkspaceFactory.Sql;
conn.DatasetType = esriDatasetType.esriDTFeatureClass;
conn.Dataset = "vwReaches";
LayerCreationParams p = new LayerCreationParams(conn);
layer = LayerFactory.Instance.CreateLayer<ArcGIS.Desktop.Mapping.FeatureLayer>(p, parent as ILayerContainerEdit);
I finally solved this by making a connection to the GeoPackage first. Then using this connection to create the layer. I suspect that this avoids ArcPro making assumptions about the uri.
CIMStandardDataConnection conn = new CIMStandardDataConnection();
conn.WorkspaceConnectionString = string.Format(@"DATABASE=C:/mydata/mygeopackage.gpkg");
conn.WorkspaceFactory = WorkspaceFactory.Sql;
conn.DatasetType = esriDatasetType.esriDTFeatureClass;
conn.Dataset = "vwReaches";
LayerCreationParams p = new LayerCreationParams(conn);
layer = LayerFactory.Instance.CreateLayer<ArcGIS.Desktop.Mapping.FeatureLayer>(p, parent as ILayerContainerEdit);