Azavea.NijPredictivePolicing.ACSAlchemistLibrary.FileFormats.ShapefileHelper.LoadShapefile C# (CSharp) Method

LoadShapefile() public static method

Imports a shapefile into the database. Do not use this to load census shapefiles.
public static LoadShapefile ( string filename, string tableName, IDataClient DbClient, ICoordinateSystem &CRS ) : bool
filename string The path of the file to import
tableName string
DbClient IDataClient The database to load the file into
CRS ICoordinateSystem
return bool
        public static bool LoadShapefile(string filename, string tableName, IDataClient DbClient, out ICoordinateSystem CRS)
        {
            CRS = null;
            if ((string.IsNullOrEmpty(filename)) || (!File.Exists(filename)))
            {
                _log.ErrorFormat("LoadShapefile failed: filename was empty or file does not exist {0}", filename);
                return false;
            }

            try
            {
                string fileWithoutExt = Path.GetFileNameWithoutExtension(filename);
                string prjFileName = Path.Combine(Path.GetDirectoryName(filename), fileWithoutExt) + ".prj";

                if (ShapefileHelper.IsForbiddenShapefileName(fileWithoutExt))
                {
                    _log.ErrorFormat("LoadShapefile failed: {0} conflicts with a reserved census shapefile name, please rename", fileWithoutExt);
                    return false;
                }

                if (File.Exists(prjFileName))
                {
                    CRS = Utilities.GetCoordinateSystemByWKTFile(prjFileName);
                }
                else
                {
                    _log.ErrorFormat("LoadShapefile failed: shapefile {0} is missing a .prj file.", filename);
                    return false;
                }

                using (DbConnection conn = DbClient.GetConnection())
                {
                    if (!ShapefileHelper.ImportShapefile(conn, DbClient, filename, tableName, (int)CRS.AuthorityCode))
                    {
                        _log.Error("LoadShapefile failed: unable to import shapefile.");
                        return false;
                    }
                }

                _log.Debug("Shapefile imported successfully...");
                return true;
            }
            catch (Exception ex)
            {
                _log.Error("Error while importing shapefile", ex);
            }

            return false;
        }