Exemplo n.º 1
0
 public void ExportTest()
 {
     SpatialiteExporter target = new SpatialiteExporter(); // TODO: Initialize to an appropriate value
     string spatialiteDatabasePath = string.Empty; // TODO: Initialize to an appropriate value
     ILayer layer = null; // TODO: Initialize to an appropriate value
     target.Export(spatialiteDatabasePath, layer);
     Assert.Inconclusive("A method that does not return a value cannot be verified.");
 }
Exemplo n.º 2
0
        private void buttonExport_Click(object sender, EventArgs e)
        {
            isExporting = true;
            this.StartExportingEvent(this, new EventArgs());

            try
            {
                string path = @"c:\temp\" + System.Guid.NewGuid().ToString() + ".spatialite";
                SpatialLiteDB.CreateNewDatabase(path);

                SpatialiteExporter exporter = new SpatialiteExporter(path);

                if (this.checkBoxExportCurrentExtent.Checked)
                {
                    exporter.Extent = this.MxDocument.ActiveView.Extent;
                }

                if (this.ExportLayers != null)
                {
                    progressBarLayer.Minimum = 0;
                    progressBarLayer.Maximum = this.ExportLayers.Count;

                    int k = 0;

                    foreach (KeyValuePair <int, ILayer> kvp in this.ExportLayers)
                    {
                        progressBarLayer.Value = ++k;

                        labelLayerName.Text = string.Format("Exporting Layer: {0} ({1} of {2})", kvp.Value.Name, k, this.ExportLayers.Count);
                        labelLayerName.Refresh();

                        DialogResult result = DialogResult.OK;

                        try
                        {
                            int srid = -1;

                            try
                            {
                                exporter.FindSRID(kvp.Value);
                            }
                            catch (InvalidSpatialReferenceException)
                            {
                            }
                            catch (Exception)
                            {
                                throw;
                            }



                            if (srid.Equals(-1))
                            {
                                result = MessageBox.Show(
                                    string.Format(
                                        "Spatial Reference: {0} ({1}) does not exist in spatialite.\n Do you wish to look up as EPSG?",
                                        kvp.Value.GetSpatialReference().Name,
                                        srid)
                                    , "Export to Spatialite", MessageBoxButtons.YesNo);

                                if (result == DialogResult.Yes)
                                {
                                    srid = exporter.FindSRID(kvp.Value, "epsg");

                                    if (srid.Equals(-1))
                                    {
                                        MessageBox.Show(
                                            string.Format(
                                                "Spatial Reference: {0} ({1}) does not exist in spatialite as EPSG either.  :( ",
                                                kvp.Value.GetSpatialReference().Name,
                                                srid)
                                            , "Export to Spatialite", MessageBoxButtons.OK);

                                        result = DialogResult.Cancel;
                                    }
                                    else
                                    {
                                        result = MessageBox.Show(
                                            string.Format(
                                                "Spatial Reference: {0} ({1}) does exist in spatialite as EPSG!",
                                                kvp.Value.GetSpatialReference().Name,
                                                srid)
                                            , "Export to Spatialite", MessageBoxButtons.OK);
                                    }
                                }
                            }

                            if (result == DialogResult.OK)
                            {
                                progressBarOperation.Value   = 0;
                                progressBarOperation.Minimum = 0;

                                exporter.StatusMessageEvent      += new SpatialiteExporter.StatusMessageDelegate(exporter_StatusMessageEvent);
                                exporter.AttributeExportProgress += new SpatialiteExporter.ExportProgressChanged(exporter_AttributeExportProgress);
                                exporter.GeometryExportProgress  += new SpatialiteExporter.ExportProgressChanged(exporter_GeometryExportProgress);
                                exporter.GeometryReadProgress    += new SpatialiteExporter.ExportProgressChanged(exporter_GeometryReadProgress);
                                exporter.AttributeReadProgress   += new SpatialiteExporter.ExportProgressChanged(exporter_AttributeReadProgress);


                                exporter.Export(kvp.Value, ((IFeatureLayer)(kvp.Value)).FeatureClass.ToOIDList(), srid, 1000);

                                // exporter.Export(kvp.Value, srid);

                                exporter.AttributeExportProgress -= exporter_AttributeExportProgress;
                                exporter.GeometryExportProgress  -= exporter_GeometryExportProgress;
                                exporter.GeometryReadProgress    -= exporter_GeometryReadProgress;
                                exporter.AttributeReadProgress   -= exporter_AttributeReadProgress;

                                MessageBox.Show(string.Format("Export to '{0}' is complete.", path), "Export to Spatialite.", MessageBoxButtons.OK);
                            }
                        }
                        catch (InvalidSpatialReferenceException ex)                        {
                            string message = "Sqlite/Spatialite Exception: \n\n{0}\n\n";

                            MessageBox.Show(string.Format(message, ex.Message),
                                            "Export To Spatialite Exception",
                                            MessageBoxButtons.OK);
                        }
                        catch (Exception)
                        {
                            throw;
                        }
                    }
                }
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                isExporting = false;
                this.StopExportingEvent(this, new EventArgs());
            }
        }