export point as shapefile

1813
5
Jump to solution
05-06-2021 12:57 AM
NareshBansal
New Contributor II

hii,

i'm working on arcgis runtime java maven application , I just want to know that how to export an sketch(point , line ,polygon) in shapefile format. 

please share sample code if available...

 

 

@MarkBaird 

Tags (2)
0 Kudos
1 Solution

Accepted Solutions
MarkBaird
Esri Regular Contributor

I'm not completely sure of your workflow here, but how are you planning on drawing your sketches?  Are you planning on using graphics and maybe the sketch editor like in this sample?

If this is your plan, then you could write some code to move these geometries into an existing shapefile.  There is API which allows you to display and potentially edit shapefiles.  The sample here shows how to open a shapefile.   The ShapefileFeatureTable class has methods for adding new features.

Remember that a shapefile can only contain one type of geometry.  For example if a shapefile schema is for points, then you can't write lines or polygons into the same file.

I would however consider if you really need to use the shapefile format here.  There are potentially better workflows for editing and sharing data, but I'd need to know a little more about the bigger picture of what you are trying to achieve.

View solution in original post

0 Kudos
5 Replies
MarkBaird
Esri Regular Contributor

I'm not completely sure of your workflow here, but how are you planning on drawing your sketches?  Are you planning on using graphics and maybe the sketch editor like in this sample?

If this is your plan, then you could write some code to move these geometries into an existing shapefile.  There is API which allows you to display and potentially edit shapefiles.  The sample here shows how to open a shapefile.   The ShapefileFeatureTable class has methods for adding new features.

Remember that a shapefile can only contain one type of geometry.  For example if a shapefile schema is for points, then you can't write lines or polygons into the same file.

I would however consider if you really need to use the shapefile format here.  There are potentially better workflows for editing and sharing data, but I'd need to know a little more about the bigger picture of what you are trying to achieve.

0 Kudos
NareshBansal
New Contributor II

exactly,  you got the plan what i am asking for ,but want to know that how can i save these geometries into shapefile format as by clicking simple save button. and another , how can i browse any shapefile into my project by using add data button on UI ,i have created.

0 Kudos
MarkBaird
Esri Regular Contributor

From your picture it looks like you have a number of point based graphics which you have added.  Assuming you have a shapefile (potentially an empty one which is set up for point geometries) you can do something like this:

 - Loop through the graphics in your graphics overlay and for each graphic obtain the geometry (a point in your example).

 - For each geometry you will need to create a feature which matches the schema of your shape file.  A feature will contain the geometry and optionally attributes too.

 - Using the ShapefileFeatureTable class use the addFeature method https://developers.arcgis.com/java/api-reference/reference/com/esri/arcgisruntime/data/FeatureTable....

(Note that ShapefileFeatureTable inherits from FeatureTable)

There isn't a specific sample showing how to add features to a shapefile, but essentially its the same for any data source so these references will help:

 - https://developers.arcgis.com/java/query-and-edit/edit/

 - https://developers.arcgis.com/java/sample-code/add-features/

As for browsing shapefiles, just use the JavaFX file chooser and look for .shp files.  

0 Kudos
NareshBansal
New Contributor II

and for browsing geopackage , what should i do. as i tried the given sample but not working.

0 Kudos
MarkBaird
Esri Regular Contributor

GeoPackages are separate to shapefiles so if you have specific questions about GeoPackages then its best if you start a fresh question.  This makes the forum easier to search for answers.

This sample shows how to display the contents of a GeoPackage https://github.com/Esri/arcgis-runtime-samples-java/tree/master/feature_layers/feature-layer-geopack...

0 Kudos