Esempio n. 1
0
        private static List <GeospatialAreaStaging> ConvertToGeospatialStagings(string responseData, DatabaseEntities dbContext, string databaseConnectionString)
        {
            var featureCollection =
                JsonConvert.DeserializeObject <FeatureCollection>(responseData, new GeometryConverter());

            if (!featureCollection.Features.Any())
            {
                throw new Exception("No geospatial area features were returned from the endpoint.");
            }

            // Clear out staging table
            var tenantID         = HttpRequestStorage.Tenant.TenantID;
            var stagingsToDelete = dbContext.GeospatialAreaStagings.ToList();

            dbContext.AllGeospatialAreaStagings.RemoveRange(stagingsToDelete);
            dbContext.SaveChangesWithNoAuditing(tenantID);

            var ogr2OgrCommandLineRunner = new Ogr2OgrCommandLineRunner(FirmaWebConfiguration.Ogr2OgrExecutable,
                                                                        Ogr2OgrCommandLineRunner.DefaultCoordinateSystemId,
                                                                        FirmaWebConfiguration.HttpRuntimeExecutionTimeout.TotalMilliseconds);

            ogr2OgrCommandLineRunner.ImportGeoJsonToMsSql(responseData,
                                                          databaseConnectionString,
                                                          "GeospatialAreaStaging",
                                                          $"SELECT {tenantID} as TenantID, Name as Name, GlobalID as ExternalID",
                                                          false);
            return(dbContext.GeospatialAreaStagings.ToList());
        }
        public IEnumerable <ValidationResult> Validate(ValidationContext validationContext)
        {
            var errors = new List <ValidationResult>();

            FileResource.ValidateFileSize(FileResourceData, errors, GeneralUtility.NameOf(() => FileResourceData));

            using (var disposableTempFile = DisposableTempFile.MakeDisposableTempFileEndingIn(".gdb.zip"))
            {
                var gdbFile = disposableTempFile.FileInfo;
                FileResourceData.SaveAs(gdbFile.FullName);

                var ogr2OgrCommandLineRunner = new Ogr2OgrCommandLineRunner(FirmaWebConfiguration.Ogr2OgrExecutable,
                                                                            Ogr2OgrCommandLineRunner.DefaultCoordinateSystemId,
                                                                            FirmaWebConfiguration.HttpRuntimeExecutionTimeout.TotalMilliseconds);

                List <string> featureClassNames = null;
                try
                {
                    featureClassNames = OgrInfoCommandLineRunner.GetFeatureClassNamesFromFileGdb(new FileInfo(FirmaWebConfiguration.OgrInfoExecutable),
                                                                                                 gdbFile,
                                                                                                 Ogr2OgrCommandLineRunner.DefaultTimeOut);
                }
                catch (Exception e)
                {
                    errors.Add(new ValidationResult("There was a problem uploading your file geodatabase. Verify it meets the requirements and is not corrupt."));
                    SitkaLogger.Instance.LogDetailedErrorMessage(e);
                }

                if (featureClassNames != null)
                {
                    var featureClasses = featureClassNames.ToDictionary(x => x,
                                                                        x =>
                    {
                        try
                        {
                            var geoJson = ogr2OgrCommandLineRunner.ImportFileGdbToGeoJson(gdbFile, x, false);
                            return(JsonTools.DeserializeObject <FeatureCollection>(geoJson));
                        }
                        catch (Exception e)
                        {
                            errors.Add(new ValidationResult($"There was a problem processing the Feature Class \"{x}\"."));
                            SitkaLogger.Instance.LogDetailedErrorMessage(e);
                            return(null);
                        }
                    }).Where(x => x.Value != null && FocusAreaLocationStaging.IsUsableFeatureCollectionGeoJson(x.Value));

                    if (!featureClasses.Any())
                    {
                        errors.Add(new ValidationResult("There are no usable Feature Classes in the uploaded file. Feature Classes must contain Polygon and/or Multi-Polygon features."));
                    }
                }
            }

            return(errors);
        }
Esempio n. 3
0
        private static void StageFeatureCollection(FeatureCollection newPrecipitationZoneFeatureCollection)
        {
            var jsonFeatureCollection = JsonConvert.SerializeObject(newPrecipitationZoneFeatureCollection);

            var ogr2OgrCommandLineRunner = new Ogr2OgrCommandLineRunner(NeptuneWebConfiguration.Ogr2OgrExecutable,
                                                                        CoordinateSystemHelper.NAD_83_HARN_CA_ZONE_VI_SRID, 600000);

            ogr2OgrCommandLineRunner.ImportGeoJsonToMsSql(jsonFeatureCollection,
                                                          NeptuneWebConfiguration.DatabaseConnectionString, "PrecipitationZoneStaging",
                                                          "ID as PrecipitationZoneKey, RainfallZo as DesignStormwaterDepthInInches",
                                                          CoordinateSystemHelper.NAD_83_HARN_CA_ZONE_VI_SRID, CoordinateSystemHelper.NAD_83_HARN_CA_ZONE_VI_SRID);
        }
Esempio n. 4
0
        private static void StageFeatureCollection(FeatureCollection newLSPCBasinFeatureCollection)
        {
            var jsonFeatureCollection = JsonConvert.SerializeObject(newLSPCBasinFeatureCollection);

            var ogr2OgrCommandLineRunner = new Ogr2OgrCommandLineRunner(NeptuneWebConfiguration.Ogr2OgrExecutable,
                                                                        CoordinateSystemHelper.NAD_83_HARN_CA_ZONE_VI_SRID, 600000);

            ogr2OgrCommandLineRunner.ImportGeoJsonToMsSql(jsonFeatureCollection,
                                                          NeptuneWebConfiguration.DatabaseConnectionString, "LSPCBasinStaging",
                                                          "LSPC_BASIN as LSPCBasinKey, Name as LSPCBasinName",
                                                          CoordinateSystemHelper.NAD_83_HARN_CA_ZONE_VI_SRID, CoordinateSystemHelper.NAD_83_HARN_CA_ZONE_VI_SRID);
        }
        private static void StageFeatureCollection(FeatureCollection newRegionalSubbasinFeatureCollection)
        {
            var jsonFeatureCollection = JsonConvert.SerializeObject(newRegionalSubbasinFeatureCollection);

            var ogr2OgrCommandLineRunner = new Ogr2OgrCommandLineRunner(NeptuneWebConfiguration.Ogr2OgrExecutable,
                                                                        CoordinateSystemHelper.NAD_83_HARN_CA_ZONE_VI_SRID, 600000);

            ogr2OgrCommandLineRunner.ImportGeoJsonToMsSql(jsonFeatureCollection,
                                                          NeptuneWebConfiguration.DatabaseConnectionString, "RegionalSubbasinStaging",
                                                          "CatchIDN as OCSurveyCatchmentID, DwnCatchIDN as OCSurveyDownstreamCatchmentID, DrainID as DrainID, Watershed as Watershed",
                                                          // transform from 2230 to 2771 here to avoid precision errors introduced by asking arc to do it
                                                          CoordinateSystemHelper.NAD_83_CA_ZONE_VI_SRID, CoordinateSystemHelper.NAD_83_HARN_CA_ZONE_VI_SRID);
        }
        public static List <ProjectLocationStagingUpdate> CreateProjectLocationStagingUpdateListFromGdb(FileInfo gdbFile, ProjectUpdateBatch projectUpdateBatch, Person currentPerson)
        {
            var ogr2OgrCommandLineRunner = new Ogr2OgrCommandLineRunner(FirmaWebConfiguration.Ogr2OgrExecutable,
                                                                        Ogr2OgrCommandLineRunner.DefaultCoordinateSystemId,
                                                                        FirmaWebConfiguration.HttpRuntimeExecutionTimeout.TotalMilliseconds);

            var featureClassNames = OgrInfoCommandLineRunner.GetFeatureClassNamesFromFileGdb(new FileInfo(FirmaWebConfiguration.OgrInfoExecutable), gdbFile, Ogr2OgrCommandLineRunner.DefaultTimeOut);

            var projectLocationStagings =
                featureClassNames.Select(x => new ProjectLocationStagingUpdate(projectUpdateBatch, currentPerson, x, ogr2OgrCommandLineRunner.ImportFileGdbToGeoJson(gdbFile, x, true), true)).ToList();

            return(projectLocationStagings);
        }
Esempio n. 7
0
        public static List <string> ImportShapefileIntoSqlTempTable(string shapeFilePath)
        {
            var connectionString = FirmaWebConfiguration.DatabaseConnectionString;

            connectionString = connectionString.Replace("Trusted_Connection=True", "trusted_connection=yes");
            var ogr2OgrCommandLineRunner = new Ogr2OgrCommandLineRunner(FirmaWebConfiguration.Ogr2OgrExecutable,
                                                                        Ogr2OgrCommandLineRunner.DefaultCoordinateSystemId,
                                                                        FirmaWebConfiguration.HttpRuntimeExecutionTimeout.TotalMilliseconds);
            var featureClassNames = OgrInfoCommandLineRunner.GetFeatureClassNamesFromShapefile(new FileInfo(FirmaWebConfiguration.OgrInfoExecutable), shapeFilePath, Ogr2OgrCommandLineRunner.DefaultTimeOut);

            ogr2OgrCommandLineRunner.ImportPolyFromShapefile(shapeFilePath, false,
                                                             GISImportTableName, GeomName, FIDName, connectionString);
            return(featureClassNames);
        }
Esempio n. 8
0
        public static List <ProjectLocationStagingUpdate> CreateProjectLocationStagingUpdateListFromKmz(FileInfo disposableTempFileFileInfo, string fileName, ProjectUpdateBatch projectUpdateBatch, FirmaSession currentFirmaSession)
        {
            var ogr2OgrCommandLineRunner = new Ogr2OgrCommandLineRunner(FirmaWebConfiguration.Ogr2OgrExecutable,
                                                                        LtInfoGeometryConfiguration.DefaultCoordinateSystemId,
                                                                        FirmaWebConfiguration.HttpRuntimeExecutionTimeout.TotalMilliseconds);

            var featureClassNames = OgrInfoCommandLineRunner.GetFeatureClassNamesFromFileKmz(new FileInfo(FirmaWebConfiguration.OgrInfoExecutable), disposableTempFileFileInfo, fileName, Ogr2OgrCommandLineRunner.DefaultTimeOut);

            var projectLocationStagings =
                featureClassNames.Select(x => new ProjectLocationStagingUpdate(projectUpdateBatch, currentFirmaSession.Person, "", ogr2OgrCommandLineRunner.ImportFileKmzToGeoJson(disposableTempFileFileInfo, true), true)).ToList();

            Check.Require(!projectLocationStagings.All(x => x.ToGeoJsonFeatureCollection().Features.All(y => y.Geometry == null)), new SitkaGeometryDisplayErrorException($"Cannot create stagings for a location when all features don't have a geometry"));
            return(projectLocationStagings);
        }
Esempio n. 9
0
        /// <summary>
        /// Overload taking a TreatmentBMPType so it can access the Custom Attributes
        /// </summary>
        /// <param name="treatmentBMPs"></param>
        /// <param name="treatmentBMPType"></param>
        /// <returns></returns>
        public static FeatureCollection ToExportGeoJsonFeatureCollection(this IEnumerable <TreatmentBMP> treatmentBMPs, TreatmentBMPType treatmentBMPType)
        {
            var featureCollection = new FeatureCollection();

            featureCollection.Features.AddRange(treatmentBMPs.Select(treatmentBMP =>
            {
                var feature = DbGeometryToGeoJsonHelper.FromDbGeometryWithNoReproject(treatmentBMP.LocationPoint4326);
                AddAllCommonPropertiesToTreatmentBMPFeature(feature, treatmentBMP);
                foreach (var ca in treatmentBMPType.TreatmentBMPTypeCustomAttributeTypes.OrderBy(x => x.SortOrder))
                {
                    feature.Properties.Add(Ogr2OgrCommandLineRunner.SanitizeStringForGdb(ca.CustomAttributeType.CustomAttributeTypeName), treatmentBMP.GetCustomAttributeValueWithUnits(ca));
                }
                return(feature);
            }));
            return(featureCollection);
        }
Esempio n. 10
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="gisFile"></param>
        /// <param name="originalFilename">This is the original name of the file as it appeared on the users file system. It is provided just for error messaging purposes.</param>
        /// <param name="organization"></param>
        /// <returns></returns>
        public static List <OrganizationBoundaryStaging> CreateOrganizationBoundaryStagingStagingListFromGdb(FileInfo gisFile, string originalFilename, Organization organization)
        {
            var ogr2OgrCommandLineRunner = new Ogr2OgrCommandLineRunner(FirmaWebConfiguration.Ogr2OgrExecutable,
                                                                        LtInfoGeometryConfiguration.DefaultCoordinateSystemId,
                                                                        FirmaWebConfiguration.HttpRuntimeExecutionTimeout.TotalMilliseconds);

            var geoJsons =
                OgrInfoCommandLineRunner.GetFeatureClassNamesFromFileGdb(new FileInfo(FirmaWebConfiguration.OgrInfoExecutable), gisFile, originalFilename, Ogr2OgrCommandLineRunner.DefaultTimeOut)
                .ToDictionary(x => x, x => ogr2OgrCommandLineRunner.ImportFileGdbToGeoJson(gisFile, x, false))
                .Where(x => OrganizationBoundaryStaging.IsUsableFeatureCollectionGeoJson(JsonTools.DeserializeObject <FeatureCollection>(x.Value)))
                .ToDictionary(x => x.Key, x => new FeatureCollection(JsonTools.DeserializeObject <FeatureCollection>(x.Value).Features.Where(OrganizationBoundaryStaging.IsUsableFeatureGeoJson).ToList()).ToGeoJsonString());

            Check.Assert(geoJsons.Count != 0, "Number of usable Feature Classes in uploaded file must be greater than 0.");

            return(geoJsons.Select(x => new OrganizationBoundaryStaging(organization, x.Key, x.Value)).ToList());
        }
Esempio n. 11
0
        public ActionResult <ParcelUpdateExpectedResultsDto> PreviewParcelLayerGDBChangesViaGeoJsonFeatureCollectionAndUploadToStaging([FromBody] ParcelLayerUpdateDto model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var waterYearDto = WaterYear.GetByWaterYearID(_dbContext, model.YearChangesToTakeEffect);

            if (waterYearDto == null)
            {
                return(BadRequest("Invalid water year selected"));
            }

            var gdbFileContents = UploadedGdb.GetUploadedGdbFileContents(_dbContext, model.UploadedGDBID);

            using var disposableTempFile = DisposableTempFile.MakeDisposableTempFileEndingIn(".gdb.zip");
            var gdbFile = disposableTempFile.FileInfo;

            System.IO.File.WriteAllBytes(gdbFile.FullName, gdbFileContents);
            try
            {
                var ogr2OgrCommandLineRunner = new Ogr2OgrCommandLineRunner(_rioConfiguration.Ogr2OgrExecutable,
                                                                            Ogr2OgrCommandLineRunner.DefaultCoordinateSystemId,
                                                                            250000000, false);
                var columns = model.ColumnMappings.Select(
                    x =>
                    $"{x.MappedColumnName} as {x.RequiredColumnName}").ToList();
                var geoJson = ogr2OgrCommandLineRunner.ImportFileGdbToGeoJson(gdbFile.FullName,
                                                                              model.ParcelLayerNameInGDB, columns, null, _logger, null, false);
                var featureCollection = GeoJsonHelpers.GetFeatureCollectionFromGeoJsonString(geoJson, 14);
                var expectedResults   = ParcelUpdateStaging.AddFromFeatureCollection(_dbContext, featureCollection, _rioConfiguration.ValidParcelNumberRegexPattern, _rioConfiguration.ValidParcelNumberPatternAsStringForDisplay, waterYearDto);
                return(Ok(expectedResults));
            }
            catch (System.ComponentModel.DataAnnotations.ValidationException e)
            {
                _logger.LogError(e.Message);

                return(BadRequest(e.Message));
            }
            catch (Exception e)
            {
                _logger.LogError(e.Message);

                return(BadRequest("Error generating preview of changes!"));
            }
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="gdbFile"></param>
        /// <param name="originalFilename">This is the original name of the file as it appeared on the users file system. It is provided just for error messaging purposes.</param>
        /// <param name="project"></param>
        /// <param name="currentFirmaSession"></param>
        /// <returns></returns>
        public static List <ProjectLocationStaging> CreateProjectLocationStagingListFromGdb(FileInfo gdbFile,
                                                                                            string originalFilename,
                                                                                            Project project,
                                                                                            FirmaSession currentFirmaSession)
        {
            var ogr2OgrCommandLineRunner = new Ogr2OgrCommandLineRunner(FirmaWebConfiguration.Ogr2OgrExecutable,
                                                                        LtInfoGeometryConfiguration.DefaultCoordinateSystemId,
                                                                        FirmaWebConfiguration.HttpRuntimeExecutionTimeout.TotalMilliseconds);

            var featureClassNames = OgrInfoCommandLineRunner.GetFeatureClassNamesFromFileGdb(new FileInfo(FirmaWebConfiguration.OgrInfoExecutable), gdbFile, originalFilename, Ogr2OgrCommandLineRunner.DefaultTimeOut);

            var projectLocationStagings =
                featureClassNames.Select(x => new ProjectLocationStaging(project, currentFirmaSession.Person, x, ogr2OgrCommandLineRunner.ImportFileGdbToGeoJson(gdbFile, x, true), true)).ToList();

            Check.Require(!projectLocationStagings.All(x => x.ToGeoJsonFeatureCollection().Features.All(y => y.Geometry == null)), new SitkaGeometryDisplayErrorException($"Cannot create stagings for a location when all features don't have a geometry."));
            return(projectLocationStagings);
        }
Esempio n. 13
0
        public static List <string> ImportGdbIntoSqlTempTable(FileInfo gdbFile)
        {
            var connectionString = FirmaWebConfiguration.DatabaseConnectionString;

            connectionString = connectionString.Replace("Trusted_Connection=True", "trusted_connection=yes");
            var ogr2OgrCommandLineRunner = new Ogr2OgrCommandLineRunner(FirmaWebConfiguration.Ogr2OgrExecutable,
                                                                        Ogr2OgrCommandLineRunner.DefaultCoordinateSystemId,
                                                                        FirmaWebConfiguration.HttpRuntimeExecutionTimeout.TotalMilliseconds);
            var featureClassNames        = OgrInfoCommandLineRunner.GetFeatureClassNamesFromFileGdb(new FileInfo(FirmaWebConfiguration.OgrInfoExecutable), gdbFile, Ogr2OgrCommandLineRunner.DefaultTimeOut, false);
            var featureClassNameToImport = string.Empty;

            if (featureClassNames.Count > 1)
            {
                featureClassNameToImport = featureClassNames
                                           .Where(x => !x.Contains("ATTACH", StringComparison.InvariantCultureIgnoreCase)).FirstOrDefault();
            }
            ogr2OgrCommandLineRunner.ImportFileGdbToSql(gdbFile, false,
                                                        GISImportTableName, GeomName, FIDName, connectionString, featureClassNameToImport);
            return(featureClassNames);
        }
Esempio n. 14
0
        public bool UpdateModel(Person currentPerson)
        {
            HttpRequestStorage.DatabaseEntities.DelineationStagings.DeleteDelineationStaging(currentPerson.DelineationStagingsWhereYouAreTheUploadedByPerson);
            HttpRequestStorage.DatabaseEntities.SaveChanges();

            using (var disposableTempFile = DisposableTempFile.MakeDisposableTempFileEndingIn(".gdb.zip"))
            {
                var gdbFile = disposableTempFile.FileInfo;
                FileResourceData.SaveAs(gdbFile.FullName);

                var ogr2OgrCommandLineRunner = new Ogr2OgrCommandLineRunner(NeptuneWebConfiguration.Ogr2OgrExecutable,
                                                                            Ogr2OgrCommandLineRunner.DefaultCoordinateSystemId,
                                                                            NeptuneWebConfiguration.HttpRuntimeExecutionTimeout.TotalMilliseconds * 10);

                try
                {
                    var featureClassNames = OgrInfoCommandLineRunner.GetFeatureClassNamesFromFileGdb(new FileInfo(NeptuneWebConfiguration.OgrInfoExecutable),
                                                                                                     gdbFile,
                                                                                                     Ogr2OgrCommandLineRunner.DefaultTimeOut);
                    if (featureClassNames != null)
                    {
                        var columns = new List <string>
                        {
                            $"{currentPerson.PersonID} as UploadedByPersonID",
                            $"{TreatmentBMPNameField} as TreatmentBMPName",
                            $"{StormwaterJurisdictionID} as StormwaterJurisdictionID"
                        };
                        ogr2OgrCommandLineRunner.ImportFileGdbToMsSql(gdbFile, featureClassNames[0], "DelineationStaging", columns,
                                                                      NeptuneWebConfiguration.DatabaseConnectionString, true, Ogr2OgrCommandLineRunner.GEOMETRY_TYPE_POLYGON);
                    }
                }
                catch (Exception e)
                {
                    SitkaLogger.Instance.LogAbridgedErrorMessage(e);
                    return(false);
                }
            }

            return(true);
        }
        public void CanCreateBoundingBoxFromGeoJson()
        {
            var          gdbFileInfo     = FileUtility.FirstMatchingFileUpDirectoryTree(@"LTInfo.Common\GdalOgr\SampleFileGeodatabase.gdb.zip");
            const string sourceLayerName = "MySampleFeatureClass";
            // Act
            // ---
            const int    totalMilliseconds        = 110000;
            const string pathToOgr2OgrExecutable  = @"C:\Program Files\GDAL\ogr2ogr.exe";
            var          ogr2OgrCommandLineRunner = new Ogr2OgrCommandLineRunner(pathToOgr2OgrExecutable, CoordinateSystemId, totalMilliseconds);
            var          geoJson = ogr2OgrCommandLineRunner.ImportFileGdbToGeoJson(gdbFileInfo, sourceLayerName, true);

            // Act
            // ---
            var boundingBox = BoundingBox.MakeBoundingBoxFromGeoJson(geoJson);

            var expectedResult = new Tuple <double, double, double, double>(-122.825678, 45.555868, -122.272895, 45.938212);

            Assert.That(expectedResult.Item1, Is.EqualTo(boundingBox.Southwest.Longitude));
            Assert.That(expectedResult.Item2, Is.EqualTo(boundingBox.Southwest.Latitude));
            Assert.That(expectedResult.Item3, Is.EqualTo(boundingBox.Northeast.Longitude));
            Assert.That(expectedResult.Item4, Is.EqualTo(boundingBox.Northeast.Latitude));
        }
        public FileResult Download(RegionalSubbasinRevisionRequestPrimaryKey regionalSubbasinRevisionRequestPrimaryKey)
        {
            var geometry = regionalSubbasinRevisionRequestPrimaryKey.EntityObject
                           .RegionalSubbasinRevisionRequestGeometry;

            var reprojectedGeometry = CoordinateSystemHelper.ProjectWebMercatorTo2230(geometry);

            var geoJson = DbGeometryToGeoJsonHelper.FromDbGeometryWithNoReproject(reprojectedGeometry);

            var serializedGeoJson = JsonConvert.SerializeObject(geoJson);

            var outputLayerName = $"BMP_{regionalSubbasinRevisionRequestPrimaryKey.EntityObject.TreatmentBMP.TreatmentBMPID}_RevisionRequest";

            using (var workingDirectory = new DisposableTempDirectory())
            {
                var outputPathForLayer =
                    Path.Combine(workingDirectory.DirectoryInfo.FullName, outputLayerName);


                var ogr2OgrCommandLineRunner = new Ogr2OgrCommandLineRunner(NeptuneWebConfiguration.Ogr2OgrExecutable,
                                                                            CoordinateSystemHelper.NAD_83_CA_ZONE_VI_SRID,
                                                                            NeptuneWebConfiguration.HttpRuntimeExecutionTimeout.TotalMilliseconds);

                ogr2OgrCommandLineRunner.ImportGeoJsonToFileGdb(serializedGeoJson, outputPathForLayer,
                                                                outputLayerName, false, true);

                using (var zipFile = DisposableTempFile.MakeDisposableTempFileEndingIn(".zip"))
                {
                    ZipFile.CreateFromDirectory(workingDirectory.DirectoryInfo.FullName, zipFile.FileInfo.FullName);
                    var fileStream = zipFile.FileInfo.OpenRead();
                    var bytes      = fileStream.ReadFully();
                    fileStream.Close();
                    fileStream.Dispose();
                    return(File(bytes, "application/zip", $"{outputLayerName}.zip"));
                }
            }
        }
        public IEnumerable <ValidationResult> Validate(ValidationContext validationContext)
        {
            var currentPerson = HttpRequestStorage.DatabaseEntities.People.Find(PersonID);

            HttpRequestStorage.DatabaseEntities.pLandUseBlockStagingDeleteByPersonID(currentPerson.PersonID);
            var errors = new List <ValidationResult>();

            FileResource.ValidateFileSize(FileResourceData, errors, GeneralUtility.NameOf(() => FileResourceData));

            using (var disposableTempFile = DisposableTempFile.MakeDisposableTempFileEndingIn(".gdb.zip"))
            {
                var gdbFile = disposableTempFile.FileInfo;
                FileResourceData.SaveAs(gdbFile.FullName);

                var ogr2OgrCommandLineRunner = new Ogr2OgrCommandLineRunner(NeptuneWebConfiguration.Ogr2OgrExecutable,
                                                                            Ogr2OgrCommandLineRunner.DefaultCoordinateSystemId,
                                                                            NeptuneWebConfiguration.HttpRuntimeExecutionTimeout.TotalMilliseconds * 10);

                List <string> featureClassNames = null;
                try
                {
                    featureClassNames = OgrInfoCommandLineRunner.GetFeatureClassNamesFromFileGdb(new FileInfo(NeptuneWebConfiguration.OgrInfoExecutable),
                                                                                                 gdbFile,
                                                                                                 Ogr2OgrCommandLineRunner.DefaultTimeOut);
                }
                catch (Exception e)
                {
                    errors.Add(new ValidationResult("There was a problem uploading your file geodatabase. Verify it meets the requirements and is not corrupt."));
                    SitkaLogger.Instance.LogDetailedErrorMessage(e);
                }

                if (featureClassNames != null)
                {
                    if (featureClassNames.Count == 0)
                    {
                        errors.Add(new ValidationResult("The file geodatabase contained no feature class. Please upload a file geodatabase containing exactly one feature class."));
                        return(errors);
                    }

                    if (featureClassNames.Count != 1)
                    {
                        errors.Add(new ValidationResult("The file geodatabase contained more than one feature class. Please upload a file geodatabase containing exactly one feature class."));
                        return(errors);
                    }

                    try
                    {
                        var columns = new List <string>
                        {
                            "PLU_Cat as PriorityLandUseType",
                            "LU_Descr as LandUseDescription",
                            "TGR as TrashGenerationRate",
                            "LU_for_TGR as LandUseForTGR",
                            "MHI as MedianHouseHoldIncome",
                            "Jurisdic as StormwaterJurisdiction",
                            "Permit as PermitType",
                            $"{PersonID} as UploadedByPersonID"
                        };
                        ogr2OgrCommandLineRunner.ImportFileGdbToMsSql(gdbFile, featureClassNames[0],
                                                                      "LandUseBlockStaging", columns,
                                                                      NeptuneWebConfiguration.DatabaseConnectionString, true,
                                                                      Ogr2OgrCommandLineRunner.GEOMETRY_TYPE_POLYGON);
                    }
                    catch (Ogr2OgrCommandLineException e)
                    {
                        if (e.Message.Contains("column does not allow nulls",
                                               StringComparison.InvariantCultureIgnoreCase))
                        {
                            errors.Add(new ValidationResult("The upload contained features with null values. All fields are required."));
                        }
                        else if (e.Message.Contains("Unrecognised field name",
                                                    StringComparison.InvariantCultureIgnoreCase))
                        {
                            errors.Add(new ValidationResult("The columns in the uploaded file did not match the Land Use Block schema. The file is invalid and cannot be uploaded."));
                        }
                        else
                        {
                            errors.Add(new ValidationResult($"There was a problem processing the Feature Class \"{featureClassNames[0]}\". The file may be corrupted or invalid."));
                            SitkaLogger.Instance.LogDetailedErrorMessage(e);
                        }
                    }
                    catch (Exception e)
                    {
                        errors.Add(new ValidationResult($"There was a problem processing the Feature Class \"{featureClassNames[0]}\". Feature Classes must contain Polygon and/or Multi-Polygon features."));
                        SitkaLogger.Instance.LogDetailedErrorMessage(e);
                    }
                }
            }

            return(errors);
        }