<?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 Re: SQLite Database to Feature Class in Data Management Questions</title>
    <link>https://community.esri.com/t5/data-management-questions/sqlite-database-to-feature-class/m-p/438887#M25057</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Oh, today it turned out that my suggestion above actually does not work because the pure sqlite3 package does not understand the AsText function used in the sql query. One would have to use the &lt;A href="https://github.com/lokkju/pyspatialite" rel="nofollow noopener noreferrer" target="_blank"&gt;pyspatialite package&lt;/A&gt; instead. Like this:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;import arcpy, os
from pyspatialite import dbapi2 as db
from contextlib import closing&amp;nbsp; 
&amp;nbsp; 
# create spatial reference from well known ID&amp;nbsp; 
wkid = 4326 # you need to know the well known ID&amp;nbsp; 
sr = arcpy.SpatialReference(wkid)&amp;nbsp; 
&amp;nbsp; 
# create feature class and add columns&amp;nbsp; 
fc= r'c:\path\to\file.gdb\featureclass'&amp;nbsp; 
fc = arcpy.management.CreateFeatureClass(os.path.dirname(fc), os.path.basename(fc), "POLYGON", spatial_reference=sr).getOutput(0)&amp;nbsp; 
arcpy.management.AddField(fc, "col1", "LONG")&amp;nbsp; 
arcpy.management.AddField(fc, "col2", "TEXT", field_length=100)&amp;nbsp; 
&amp;nbsp; 
# insert rows from sqlite to the feature class&amp;nbsp; 
with arcpy.da.InsertCursor(fc, ["SHAPE@", "col1", "col2"]) as ic:&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; with closing(db.connect(r'c:\path\to\database.sqlite')) as conn:&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; cr = conn.cursor()&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; for row in cr.execute("select AsText(geom), col1, col2 from mytable;"):&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; shape = arcpy.FromWKT(row[0], wkid)&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ic.insertRow([shape] + row[1:])&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; del cr&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; del ic&amp;nbsp; &lt;/PRE&gt;&lt;P&gt;Filip.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sat, 11 Dec 2021 19:37:59 GMT</pubDate>
    <dc:creator>FilipKrál</dc:creator>
    <dc:date>2021-12-11T19:37:59Z</dc:date>
    <item>
      <title>SQLite Database to Feature Class</title>
      <link>https://community.esri.com/t5/data-management-questions/sqlite-database-to-feature-class/m-p/438883#M25053</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello,&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am somewhat new to programming and the SQLite world. I am looking for a way to take data from and SQLite DB and populate feature classes. The feature classes are all polygons and the intent is to get their shape from the Well Known Text field within the SQLite DB. I also need to populate two other fields in the feature class where the data is coming from the SQLite DB.&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any help would be appreciated.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 19 Nov 2014 15:19:23 GMT</pubDate>
      <guid>https://community.esri.com/t5/data-management-questions/sqlite-database-to-feature-class/m-p/438883#M25053</guid>
      <dc:creator>RyanFortier</dc:creator>
      <dc:date>2014-11-19T15:19:23Z</dc:date>
    </item>
    <item>
      <title>Re: SQLite Database to Feature Class</title>
      <link>https://community.esri.com/t5/data-management-questions/sqlite-database-to-feature-class/m-p/438884#M25054</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Did you look at this Help page? &lt;A href="http://resources.arcgis.com/en/help/main/10.2/index.html#//019v0000001w000000" title="http://resources.arcgis.com/en/help/main/10.2/index.html#//019v0000001w000000"&gt;ArcGIS Help (10.2, 10.2.1, and 10.2.2)&lt;/A&gt; &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 02 May 2015 05:50:26 GMT</pubDate>
      <guid>https://community.esri.com/t5/data-management-questions/sqlite-database-to-feature-class/m-p/438884#M25054</guid>
      <dc:creator>XanderBakker</dc:creator>
      <dc:date>2015-05-02T05:50:26Z</dc:date>
    </item>
    <item>
      <title>Re: SQLite Database to Feature Class</title>
      <link>https://community.esri.com/t5/data-management-questions/sqlite-database-to-feature-class/m-p/438885#M25055</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;What format is the polygon data? SpatiaLite or?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 05 May 2015 20:13:10 GMT</pubDate>
      <guid>https://community.esri.com/t5/data-management-questions/sqlite-database-to-feature-class/m-p/438885#M25055</guid>
      <dc:creator>LanceShipman</dc:creator>
      <dc:date>2015-05-05T20:13:10Z</dc:date>
    </item>
    <item>
      <title>Re: SQLite Database to Feature Class</title>
      <link>https://community.esri.com/t5/data-management-questions/sqlite-database-to-feature-class/m-p/438886#M25056</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Ryan,&lt;/P&gt;&lt;P&gt;&lt;A href="https://community.esri.com/migrated-users/3100" target="_blank"&gt;Xander Bakker&lt;/A&gt;​ points to a good place where it is also explained that you can connect to sqlite database directly from ArcGIS (from about 10.2 above). Once you establish connection I imagine you could simply use the &lt;A href="http://resources.arcgis.com/en/help/main/10.2/index.html#//001700000035000000" rel="nofollow noopener noreferrer" target="_blank"&gt;Copy Features tool&lt;/A&gt;.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If for some reason you want to do it in a different way, something like &lt;A href="http://resources.arcgis.com/en/help/main/10.1/index.html#/FromWKT/018v0000008s000000/" rel="nofollow noopener noreferrer" target="_blank"&gt;arcpy.FromWKT&lt;/A&gt;​ should help. Say you have an SQLite table with a polygon column 'geom' and other integer column 'col1' and varchar column 'col2'. I would try something like this:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;import arcpy, sqlite3, os
from contextlib import closing

# create spatial reference from well known ID
wkid = 4326 # you need to know the well known ID
sr = arcpy.SpatialReference(wkid)

# create feature class and add columns
fc= r'c:\path\to\file.gdb\featureclass'
fc = arcpy.management.CreateFeatureClass(os.path.dirname(fc), os.path.basename(fc), "POLYGON", spatial_reference=sr).getOutput(0)
arcpy.management.AddField(fc, "col1", "LONG")
arcpy.management.AddField(fc, "col2", "TEXT", field_length=100)

# insert rows from sqlite to the feature class
with arcpy.da.InsertCursor(fc, ["SHAPE@", "col1", "col2"]) as ic:
&amp;nbsp;&amp;nbsp;&amp;nbsp; with closing(sqlite3.connect(r'c:\path\to\database.db')) as conn:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; cr = conn.cursor()
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; for row in cr.execute("select AsText(geom), col1, col2 from mytable;"):
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; shape = arcpy.FromWKT(row[0], wkid)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ic.insertRow([shape] + row[1:])
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; del cr
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; del ic&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You'll probably need to tweak this because I haven't tested this really but I hope it gives you some pointers.&lt;/P&gt;&lt;P&gt;Let us know how you get on. I'd quite like to know what works best for you in the end.&lt;/P&gt;&lt;P&gt;Filip.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 19:37:56 GMT</pubDate>
      <guid>https://community.esri.com/t5/data-management-questions/sqlite-database-to-feature-class/m-p/438886#M25056</guid>
      <dc:creator>FilipKrál</dc:creator>
      <dc:date>2021-12-11T19:37:56Z</dc:date>
    </item>
    <item>
      <title>Re: SQLite Database to Feature Class</title>
      <link>https://community.esri.com/t5/data-management-questions/sqlite-database-to-feature-class/m-p/438887#M25057</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Oh, today it turned out that my suggestion above actually does not work because the pure sqlite3 package does not understand the AsText function used in the sql query. One would have to use the &lt;A href="https://github.com/lokkju/pyspatialite" rel="nofollow noopener noreferrer" target="_blank"&gt;pyspatialite package&lt;/A&gt; instead. Like this:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;import arcpy, os
from pyspatialite import dbapi2 as db
from contextlib import closing&amp;nbsp; 
&amp;nbsp; 
# create spatial reference from well known ID&amp;nbsp; 
wkid = 4326 # you need to know the well known ID&amp;nbsp; 
sr = arcpy.SpatialReference(wkid)&amp;nbsp; 
&amp;nbsp; 
# create feature class and add columns&amp;nbsp; 
fc= r'c:\path\to\file.gdb\featureclass'&amp;nbsp; 
fc = arcpy.management.CreateFeatureClass(os.path.dirname(fc), os.path.basename(fc), "POLYGON", spatial_reference=sr).getOutput(0)&amp;nbsp; 
arcpy.management.AddField(fc, "col1", "LONG")&amp;nbsp; 
arcpy.management.AddField(fc, "col2", "TEXT", field_length=100)&amp;nbsp; 
&amp;nbsp; 
# insert rows from sqlite to the feature class&amp;nbsp; 
with arcpy.da.InsertCursor(fc, ["SHAPE@", "col1", "col2"]) as ic:&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; with closing(db.connect(r'c:\path\to\database.sqlite')) as conn:&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; cr = conn.cursor()&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; for row in cr.execute("select AsText(geom), col1, col2 from mytable;"):&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; shape = arcpy.FromWKT(row[0], wkid)&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ic.insertRow([shape] + row[1:])&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; del cr&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; del ic&amp;nbsp; &lt;/PRE&gt;&lt;P&gt;Filip.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 19:37:59 GMT</pubDate>
      <guid>https://community.esri.com/t5/data-management-questions/sqlite-database-to-feature-class/m-p/438887#M25057</guid>
      <dc:creator>FilipKrál</dc:creator>
      <dc:date>2021-12-11T19:37:59Z</dc:date>
    </item>
  </channel>
</rss>

