Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Short answer: you need to use own customized SQLite as Android Native Library, like with other NDK libraries. The tricky part is to get useful not so trivial C# API for the database. Xamarin docs seems to have guides for very simple single method APIs only.</p> <p>As I am way more familiar to Java than .Net, then I used combination of Android Java library (.jar) and Android native library (.so). Android Java library has already Java API wrapper for the database, it is exactly the same wrapper as can be used in the usual Android Java applications. Of course, technically direct access of the native library from C# would be also possible, so java/jar could be excluded from the story. If you know good tools for that, let me know also.</p> <ol> <li>Create .jar binding project for Xamarin, add it to the same solution as your Android project</li> <li>Add jsqlite.jar to Jars folder of the <em>bindings</em> project. Get it from here: <a href="https://www.dropbox.com/s/6g5ikv5ou6sttds/jsqlite.jar" rel="noreferrer">jsqlite.jar</a></li> <li>Add native library binaries (libjsqlite.so and libproj.so) to your <em>application</em> project, create folder libs/armeabi for this. Get these from <a href="https://github.com/nutiteq/hellomap3d/tree/master/AdvancedMap3D/extlibs/armeabi" rel="noreferrer">Nutiteq AdvancedMap3D project</a></li> <li>Define the .so files as AndroidNativeLibrary, and set Copy to Output Directory</li> <li>Fix binding definitions to remove build errors. Add following to <em>Transforms/Metadata.xml</em> of your bindings project:</li> </ol> <pre class="lang-xml prettyprint-override"><code>&lt;remove-node path="/api/package[@name='jsqlite']/class[@name='Backup']/field[@name='handle']" /&gt; &lt;remove-node path="/api/package[@name='jsqlite']/class[@name='Database']/field[@name='handle']"/&gt; &lt;attr path="/api/package[@name='jsqlite']" name="managedName"&gt;jsqlite&lt;/attr&gt; </code></pre> <p>This should generate you working C# API to bundled SQLite, together with <strong>Spatialite, Proj.4 and GEOS included</strong>. The jsqlite DB API itself is different from other C# SQLite APIs, you need to use callback classes. See following examples To check versions of the modules:</p> <pre class="lang-cs prettyprint-override"><code>try { db.Open ("/sdcard/mapxt/estonia-latest-map.sqlite", Constants.SqliteOpenReadonly); // show versions to verify that modules are there db.Exec ("SELECT spatialite_version(), proj4_version(), geos_version(), sqlite_version()", new GeneralQryResult ()); } catch (jsqlite.Exception ex) { Log.Error( ex.LocalizedMessage ); } ... // prints query results as text public class GeneralQryResult : Java.Lang.Object, ICallback { public bool Newrow (string[] rowdata) { string row = ""; foreach (var data in rowdata) { row += data + " | "; } Log.Info(row); return false; } public void Types (string[] types) { // never called really } public void Columns (string[] cols){ Log.Debug ("Query result:"); string row = ""; foreach (var col in cols) { row += col + " | "; } Log.Info (row); } } </code></pre> <p>Finally now a query of real spatial data, using <a href="https://components.xamarin.com/view/NutiteqMapsSDK" rel="noreferrer" title="Nutiteq 3D SDK with Xamarin">Nutiteq 3D Maps SDK for Xamarin</a> to visualize it:</p> <pre><code>// Spatialite query, show results on map // 1. create style and layer for data LineStyle.Builder lineStyleBuilder = new LineStyle.Builder (); lineStyleBuilder.SetColor (NutiteqComponents.Color.Argb(0xff, 0x5C, 0x40, 0x33)); //brown lineStyleBuilder.SetWidth (0.05f); LineStyle lineStyle = lineStyleBuilder.Build (); GeometryLayer geomLayer = new GeometryLayer (view.Layers.BaseLayer.Projection); view.Layers.AddLayer (geomLayer); // 2. do the query, pass results to the layer Database db = new Database (); try { db.Open ("/sdcard/mapxt/estonia-latest-map.sqlite", Constants.SqliteOpenReadonly); // spatial query. Limit to 1000 objects to avoid layer overloading String qry = "SELECT id, HEX(AsBinary(Transform(geometry,3857))), sub_type, name FROM ln_railway LIMIT 1000"; db.Exec (qry, new SpatialQryResult (geomLayer, lineStyle)); } catch (jsqlite.Exception ex) { Log.Error( ex.LocalizedMessage ); } ... // adds query results to given layer, with given style public class SpatialQryResult : Java.Lang.Object, ICallback { GeometryLayer _geomLayer; Style _geomStyle; public SpatialQryResult(GeometryLayer geomLayer, Style geomStyle){ _geomLayer = geomLayer; _geomStyle = geomStyle; } public bool Newrow (string[] rowdata) { string id = rowdata [0]; string geomHex = rowdata [1]; string type = rowdata [2]; string name = rowdata [3]; Label label; if (name != null &amp;&amp; name.Length &gt; 1) { label = new DefaultLabel (name, type); } else { label = null; } Geometry[] lineGeoms = WkbRead.ReadWkb(new ByteArrayInputStream(Utils .HexStringToByteArray(geomHex)), rowdata); // following fails if not Line, change for other geometries foreach (Line lineGeom in lineGeoms) { _geomLayer.Add(new Line(lineGeom.VertexList, label, (LineStyle)_geomStyle, _geomLayer)); } return false; } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload