# Loading a shape file to SQLite

**URL:** <https://community.thinkgeo.com/t/loading-a-shape-file-to-sqlite/3772>\
**Category:** WPF\
**Created:** [February 6, 2015, 2:14pm UTC](https://community.thinkgeo.com/t/loading-a-shape-file-to-sqlite/3772 "2015-02-06T14:14:33Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Peter3](https://community.thinkgeo.com/letter_avatar_proxy/v4/letter/p/958977/32.png) [@Peter3](https://community.thinkgeo.com/u/Peter3)\
**Post date:** [February 6, 2015, 2:14pm UTC](https://community.thinkgeo.com/t/loading-a-shape-file-to-sqlite/3772/1 "2015-02-06T14:14:33Z")

</div>

I&nbsp;need&nbsp;a&nbsp;strategy&nbsp;for&nbsp;bulk&nbsp;loading&nbsp;a&nbsp;shape&nbsp;file&nbsp;into&nbsp;a&nbsp;SQLite&nbsp;db.  
  
  
  
Didn’t&nbsp;find&nbsp;a&nbsp;sample&nbsp;on&nbsp;it&nbsp;and&nbsp;the&nbsp;feature&nbsp;source&nbsp;only&nbsp;expose&nbsp;a&nbsp;GetAllFeatures()&nbsp;member.  
  
  
  
I&nbsp;would&nbsp;prefer&nbsp;a&nbsp;DataReader&nbsp;pattern&nbsp;for&nbsp;this&nbsp;task.  
  
  
  
Is&nbsp;it&nbsp;an&nbsp;option&nbsp;exist&nbsp;in&nbsp;MapSuite?  
  
  
  
Regards  
  
Peter

---

<div class="post-metadata">

**Author:** ![Johnny](https://community.thinkgeo.com/user_avatar/community.thinkgeo.com/johnny/32/19044_2.png) [@Johnny](https://community.thinkgeo.com/u/Johnny)\
**Post date:** [February 8, 2015, 9:14pm UTC](https://community.thinkgeo.com/t/loading-a-shape-file-to-sqlite/3772/2 "2015-02-08T21:14:56Z")

</div>

Hi&nbsp;Peter,

Map&nbsp;Suite&nbsp;supports&nbsp;both&nbsp;Shape&nbsp;file&nbsp;and&nbsp;Sqlite  
data&nbsp;formats,&nbsp;also&nbsp;including&nbsp;the&nbsp;conversion&nbsp;between&nbsp;them&nbsp;as&nbsp;well,&nbsp;but&nbsp;one  
requirement&nbsp;is&nbsp;that&nbsp;we&nbsp;need&nbsp;some&nbsp;codes&nbsp;here,&nbsp;just&nbsp;shown&nbsp;as&nbsp;following:

> `ShapeFileFeatureSource shapefileFeatureSource = ``new`&nbsp;`ShapeFileFeatureSource(@``"File Path Name"``, ShapeFileReadWriteMode.ReadOnly);`  
> `shapefileFeatureSource.Open();`  
> `SqliteFeatureSource sqliteFeatureSource = ``new`&nbsp;`SqliteFeatureSource(@``"Data Source=..."``, ``"table_name"``, ``"id"``, ``"geometry"``);`  
> `sqliteFeatureSource.Open();`  
> &nbsp;  
> `// Insert data from a shapefile into the new database`  
> `sqliteFeatureSource.BeginTransaction();`  
> `for`&nbsp;`(``int`&nbsp;`i = 1; i < shapefileFeatureSource.GetCount(); i++)`  
> `{`  
> `    ``Feature feature = shapefileFeatureSource.GetFeatureById(i.ToString(),ReturningColumnsType.AllColumns);`  
> `    ``sqliteFeatureSource.AddFeature(feature);`  
> `}`  
> &nbsp;  
> `sqliteFeatureSource.CommitTransaction();`

  
Thanks,  
  
Johnny

---

<div class="post-metadata">

**Author:** ![Peter3](https://community.thinkgeo.com/letter_avatar_proxy/v4/letter/p/958977/32.png) [@Peter3](https://community.thinkgeo.com/u/Peter3)\
**Post date:** [February 9, 2015, 3:08am UTC](https://community.thinkgeo.com/t/loading-a-shape-file-to-sqlite/3772/3 "2015-02-09T03:08:16Z")

</div>

Hi&nbsp;Johnny,  
  
Elegant&nbsp;solution&nbsp;-&nbsp;right&nbsp;on&nbsp;spot.  
  
  
  
But&nbsp;are&nbsp;featureIds&nbsp;guaranteed&nbsp;to&nbsp;be&nbsp;continuous&nbsp;in&nbsp;[1&nbsp;…&nbsp;FeatureCount]?  
  
  
  
What&nbsp;happens&nbsp;if&nbsp;a&nbsp;feature&nbsp;was&nbsp;deleted&nbsp;from&nbsp;the&nbsp;shape&nbsp;file&nbsp;in&nbsp;the&nbsp;middle&nbsp;of&nbsp;the&nbsp;sequence&nbsp;prior&nbsp;to&nbsp;this&nbsp;import&nbsp;(I&nbsp;don’t&nbsp;know&nbsp;the&nbsp;history&nbsp;of&nbsp;all&nbsp;the&nbsp;files&nbsp;I’m&nbsp;planning&nbsp;to&nbsp;import…)?  
  
  
  
Thanks,  
  
Peter

---

<div class="post-metadata">

**Author:** ![Johnny](https://community.thinkgeo.com/user_avatar/community.thinkgeo.com/johnny/32/19044_2.png) [@Johnny](https://community.thinkgeo.com/u/Johnny)\
**Post date:** [February 9, 2015, 9:12pm UTC](https://community.thinkgeo.com/t/loading-a-shape-file-to-sqlite/3772/4 "2015-02-09T21:12:04Z")

</div>

Hi&nbsp;Peter,&nbsp;  
&nbsp;&nbsp;  
&nbsp;All&nbsp;these&nbsp;problems&nbsp;have&nbsp;been&nbsp;taken&nbsp;into&nbsp;account,&nbsp;thus&nbsp;if&nbsp;you&nbsp;are&nbsp;using&nbsp;ShapeFielFeatureSource,&nbsp;the&nbsp;featureIds&nbsp;will&nbsp;be&nbsp;guaranteed&nbsp;to&nbsp;be&nbsp;continuous,&nbsp;the&nbsp;deleted&nbsp;or&nbsp;invalid&nbsp;records&nbsp;will&nbsp;be&nbsp;skipped&nbsp;as&nbsp;well.&nbsp;  
&nbsp;&nbsp;  
&nbsp;Thanks,&nbsp;  
&nbsp;Johnny
