<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic How do programmatically compress/compact a shapefile in .NET Maps SDK Questions</title>
    <link>https://community.esri.com/t5/net-maps-sdk-questions/how-do-programmatically-compress-compact-a/m-p/1406748#M12605</link>
    <description>&lt;P&gt;I have written a program in VB.net, using esriarcgisruntime 200, to add shapes to a shapefile. I have created the empty shapefile in QGIS. My program then adds a number of features. So far, so good - I can see all the added features in QGIS.&lt;/P&gt;&lt;P&gt;I then run the program a second time. The size of the shapefile doubles, and QGIS says the shapefile is corrrupt. I'm not sure what I've done wrong. I was hoping that compressing or compacting the shapefile may help. I will be running my program frequently, so shapefile size will be an ongoing problem - at the moment it just grows without limit. What is the correct procedure for deleting all features from a shapefile, and then adding new ones.&lt;/P&gt;&lt;P&gt;The code I am using the delete existing features is below. The process is:&lt;BR /&gt;line 3: Load the shapefile&lt;/P&gt;&lt;P&gt;Line 11: Query the shapefile to retrieve all features&lt;/P&gt;&lt;P&gt;Line 12: Delete all retrieved features. I do this in reverse order of FID in case it matters&lt;/P&gt;&lt;P&gt;Line 13: Close the shapefile in the hope it will automatically compact.&lt;/P&gt;&lt;LI-CODE lang="c"&gt;        Dim Shapefile = $"{Application.StartupPath}\DXCC.shp"
        Dim sft As New ShapefileFeatureTable(Shapefile)
        Dim fqr As FeatureQueryResult, qp As New QueryParameters
        Await sft.LoadAsync()
        ' Delete all existing features
        With qp
            .WhereClause = "1=1"            ' get all features
            .OrderByFields.Add(New OrderBy("FID", SortOrder.Descending))    ' sort by descending order of FID
            .ReturnGeometry = False
        End With
        fqr = Await sft.QueryFeaturesAsync(qp)
        Await sft.DeleteFeaturesAsync(fqr.ToList)
        sft.Close()&lt;/LI-CODE&gt;&lt;P&gt;Following this, there is code to insert new features.&lt;/P&gt;&lt;P&gt;When run the first time, and there is no existing data to delete, the new features are added, and all is fine.&lt;/P&gt;&lt;P&gt;When run a subsequent time, I get a shapefile twice the size, and one that QGIS believes is corrupt.&lt;/P&gt;&lt;P&gt;Any ideas what I've done wrong?&lt;/P&gt;</description>
    <pubDate>Sat, 06 Apr 2024 00:57:31 GMT</pubDate>
    <dc:creator>MarcHillman</dc:creator>
    <dc:date>2024-04-06T00:57:31Z</dc:date>
    <item>
      <title>How do programmatically compress/compact a shapefile</title>
      <link>https://community.esri.com/t5/net-maps-sdk-questions/how-do-programmatically-compress-compact-a/m-p/1406748#M12605</link>
      <description>&lt;P&gt;I have written a program in VB.net, using esriarcgisruntime 200, to add shapes to a shapefile. I have created the empty shapefile in QGIS. My program then adds a number of features. So far, so good - I can see all the added features in QGIS.&lt;/P&gt;&lt;P&gt;I then run the program a second time. The size of the shapefile doubles, and QGIS says the shapefile is corrrupt. I'm not sure what I've done wrong. I was hoping that compressing or compacting the shapefile may help. I will be running my program frequently, so shapefile size will be an ongoing problem - at the moment it just grows without limit. What is the correct procedure for deleting all features from a shapefile, and then adding new ones.&lt;/P&gt;&lt;P&gt;The code I am using the delete existing features is below. The process is:&lt;BR /&gt;line 3: Load the shapefile&lt;/P&gt;&lt;P&gt;Line 11: Query the shapefile to retrieve all features&lt;/P&gt;&lt;P&gt;Line 12: Delete all retrieved features. I do this in reverse order of FID in case it matters&lt;/P&gt;&lt;P&gt;Line 13: Close the shapefile in the hope it will automatically compact.&lt;/P&gt;&lt;LI-CODE lang="c"&gt;        Dim Shapefile = $"{Application.StartupPath}\DXCC.shp"
        Dim sft As New ShapefileFeatureTable(Shapefile)
        Dim fqr As FeatureQueryResult, qp As New QueryParameters
        Await sft.LoadAsync()
        ' Delete all existing features
        With qp
            .WhereClause = "1=1"            ' get all features
            .OrderByFields.Add(New OrderBy("FID", SortOrder.Descending))    ' sort by descending order of FID
            .ReturnGeometry = False
        End With
        fqr = Await sft.QueryFeaturesAsync(qp)
        Await sft.DeleteFeaturesAsync(fqr.ToList)
        sft.Close()&lt;/LI-CODE&gt;&lt;P&gt;Following this, there is code to insert new features.&lt;/P&gt;&lt;P&gt;When run the first time, and there is no existing data to delete, the new features are added, and all is fine.&lt;/P&gt;&lt;P&gt;When run a subsequent time, I get a shapefile twice the size, and one that QGIS believes is corrupt.&lt;/P&gt;&lt;P&gt;Any ideas what I've done wrong?&lt;/P&gt;</description>
      <pubDate>Sat, 06 Apr 2024 00:57:31 GMT</pubDate>
      <guid>https://community.esri.com/t5/net-maps-sdk-questions/how-do-programmatically-compress-compact-a/m-p/1406748#M12605</guid>
      <dc:creator>MarcHillman</dc:creator>
      <dc:date>2024-04-06T00:57:31Z</dc:date>
    </item>
  </channel>
</rss>

