/// <summary>
        /// Adding a country files kml to sql server
        /// </summary>
        public static void AddCountryKml(string kmlFile)
        {
            var fileStream = File.Open(kmlFile, FileMode.Open);
            var mapper     = new Kml2SqlMapper(fileStream);

            var ap = new ApirsDatabase();

            using (var connection = new SqlConnection(ap.Database.Connection.ConnectionString))
            {
                connection.Open();
                var createTableCommand = mapper.GetCreateTableCommand(connection);
                createTableCommand.ExecuteNonQuery();

                foreach (var mapFeature in mapper.GetMapFeatures())
                {
                    try
                    {
                        var command = mapFeature.GetInsertCommand();
                        command.Connection = connection;
                        command.ExecuteNonQuery();
                    }
                    catch
                    {
                        continue;
                    }
                }
            }
        }
예제 #2
0
 public Uploader(string filePath, Kml2SqlConfig configuration)
 {
     using (var stream = File.OpenRead(filePath))
     {
         Mapper = new Kml2SqlMapper(stream, configuration);
     }
 }
예제 #3
0
파일: Tests.cs 프로젝트: query-wow/KML2SQL
 public void TestGetScript()
 {
     using (var stream = File.OpenRead(@"TestData\npa.kml"))
     {
         var mapper = new Kml2SqlMapper(stream);
         mapper.Configuration.TableName = _tablePrefix + "NPA";
         mapper.Configuration.GeoType   = PolygonType.Geography;
         var places = mapper.GetMapFeatures();
         var query  = places.First().GetInsertQuery();
         Assert.IsNotNull(query);
         Assert.IsTrue(query.Length > 0);
     }
 }
예제 #4
0
        public string importKML(string path, int codUser, string filename)
        {
            try
            {
                valida = new Classes.validacao();



                fileStream = File.Open(path, FileMode.Open);
                var mapper = new Kml2SqlMapper(fileStream);
                var sb     = new StringBuilder();
                sb.Clear();
                var lista    = mapper.GetMapFeatures().ToList();
                int arquafet = 0;
                sb.Append(" Declare @count int ");
                for (int i = 0; i < lista.Count(); i++)
                {
                    if (lista[i].ShapeType.ToString() == "Point" && lista[i].Name.ToString() != "Untitled Placemark" && lista[i].Name.ToString() != "")
                    {
                        arquafet++;
                        string lat = lista[i].Coordinates[0].Latitude.ToString().Replace(",", ".");
                        string lng = lista[i].Coordinates[0].Longitude.ToString().Replace(",", ".");

                        if (lista[i].Name.Contains('-') && lista[i].Name.Contains('.'))
                        {
                            serie = lista[i].Name.Split('-')[0];
                            if (lista[i].Name.Split('-')[1].Contains("."))
                            {
                                ini = lista[i].Name.Split('-')[1].Split('.')[0];
                                fim = lista[i].Name.Split('-')[1].Split('.')[1];
                            }
                            else
                            {
                                ini = lista[i].Name.Split('-')[1];
                                fim = lista[i].Name.Split('-')[1];
                            }
                        }
                        else if (lista[i].Name.Contains('.'))
                        {
                            ini = lista[i].Name.Split('.')[0];
                            fim = lista[i].Name.Split('.')[1];
                        }
                        else if (lista[i].Name.Contains('-'))
                        {
                            serie = lista[i].Name.Split('-')[0];
                            ini   = lista[i].Name.Split('-')[1];
                            fim   = lista[i].Name.Split('-')[1];
                        }

                        else
                        {
                            ini = lista[i].Name;
                            fim = lista[i].Name;
                        }


                        //ini = lista[i].Name.Split('-')[0];
                        //fim = lista[i].Name.Split('-')[1];


                        string shape = "geometry::STGeomFromText('POINT(" + lng + " " + lat + ")',4326)";
                        sb.Append(" SELECT @count = COUNT(*) FROM " + tabela +
                                  " IF(@count > 0) " +
                                  " BEGIN " +
                                  " INSERT INTO " + tabela + " " + colunas1 + "  VALUES(((SELECT TOP 1 " + pk + " FROM " + tabela + " ORDER BY " + pk + " DESC) + 1),'" + ini + "'," + valida.prepDB(lista[i].Id.ToString()) + "," + shape + "," + valida.prepDB(filename) + ",'" + datanow + "'," + valida.prepDB(codUser.ToString()) + "," + valida.prepDB(ddlEquipe.Text) + "," + valida.validaData(ddllocal.Text) + ",'" + fim + "','" + serie + "') " +
                                  " END " +
                                  " ELSE " +
                                  " BEGIN " +
                                  " INSERT INTO " + tabela + " " + colunas1 + " VALUES(1,'" + ini + "'," + valida.prepDB(lista[i].Id.ToString()) + "," + shape + "," + valida.prepDB(filename) + ",'" + datanow + "'," + valida.prepDB(codUser.ToString()) + "," + valida.prepDB(ddlEquipe.Text) + "," + valida.validaData(ddllocal.Text) + ",'" + fim + "','" + serie + "')" +
                                  " END ");
                    }
                }

                conexao.commandExec(sb.ToString());

                fileStream.Close();
                fileStream.Dispose();


                return("" + lista.Count() + "," + arquafet);
            }catch (Exception ex)
            {
                fileStream.Close();
                fileStream.Dispose();
                return("Erro : " + ex.Message);
            }
        }
예제 #5
0
 public Uploader(FileStream stream, Kml2SqlConfig configuration)
 {
     Mapper = new Kml2SqlMapper(stream, configuration);
 }