public static void Import(DatabaseImportParameters parameters, Action <string> updateStatus)
        {
            UpdateStatus = updateStatus;

            // Configure database
            FluentConfiguration.Configure(parameters.ConnectionString, parameters.DropAndCreate);

            var normalRoutes = new List <NormalRoute>();

            // Import normal routes
            if (!string.IsNullOrWhiteSpace(parameters.NormalRoutePath))
            {
                normalRoutes = ImportNormalRoutes(parameters.NormalRoutePath);
            }

            // Import gravity vectors
            if (!string.IsNullOrWhiteSpace(parameters.GravityVectorPath))
            {
                ImportGravityVectors(syncRoot, parameters.GravityVectorPath, normalRoutes);
            }

            // Import deviation map
            if (!string.IsNullOrWhiteSpace(parameters.DeviationMapPath))
            {
                ImportDeviationCells(parameters.DeviationMapPath);
            }

            // Import near-miss map
            if (!string.IsNullOrWhiteSpace(parameters.NearMissMapPath))
            {
                ImportNearMissMap(parameters.NearMissMapPath);
            }
        }
Exemple #2
0
 protected void Application_Start()
 {
     FluentConfiguration.Configure();
     AreaRegistration.RegisterAllAreas();
     GlobalConfiguration.Configure(WebApiConfig.Register);
     FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
     RouteConfig.RegisterRoutes(RouteTable.Routes);
     BundleConfig.RegisterBundles(BundleTable.Bundles);
 }
Exemple #3
0
 static void Main()
 {
     XmlConfigurator.Configure();
     FluentConfiguration.Configure(generateTables: true);
     SessionManager.Session.Transaction.Begin();
     ImportMunicipalities();
     ImportCounties();
     SessionManager.Session.Transaction.Commit();
 }
Exemple #4
0
        private static void Run(string[] args)
        {
            var parser = new CommandLineParser.CommandLineParser();

            var connectionStringArg = new ValueArgument <string>(
                'c', "connectionstring", "Connection string to the PostgreSQL database");

            var dropAndCreateArg = new ValueArgument <bool>(
                'd', "drop", "Drop and recreate the database");

            var pathArg = new ValueArgument <string>(
                'g', "gv-merged-path", "Path to a folder containing gravity vector files");

            var normalRoutePathArg = new ValueArgument <string>(
                'n', "normal-route-path", "Path to a file containing normal route linestrings");

            var deviationCellsPathArg = new ValueArgument <string>(
                'm', "deviation-cells-path", "Path to a file containing deviation map cells");

            parser.Arguments.Add(connectionStringArg);
            parser.Arguments.Add(dropAndCreateArg);
            parser.Arguments.Add(pathArg);
            parser.Arguments.Add(normalRoutePathArg);
            parser.Arguments.Add(deviationCellsPathArg);
            parser.ParseCommandLine(args);

            bool dropAndCreate = dropAndCreateArg.Parsed ? dropAndCreateArg.Value : true;

            if (dropAndCreate)
            {
                Log.Info("You have specified that the schema should be dropped and recreated. Press ctrl-c now to cancel this program.");
                Thread.Sleep(5000);
            }

            var connectionString = connectionStringArg.Value;

            ;
            Log.Info("Configuring database..");
            FluentConfiguration.Configure(connectionString, dropAndCreate);
            Log.Info("Database connected!");

            List <NormalRoute> normalRoutes = null;

            if (normalRoutePathArg.Parsed)
            {
                var path = Path.GetFullPath(normalRoutePathArg.Value);

                if (File.Exists(path))
                {
                    normalRoutes = DatabaseImport.ImportNormalRoutes(path);
                }
                else
                {
                    Log.Error($"The path {path} does not exist");
                    return;
                }
            }
            else
            {
                if (pathArg.Parsed)
                {
                    Log.Error("You have not specified a normal route file. Press ctrl-c now to cancel this program, or wait to attempt loading gravity vectors.");
                }
                else
                {
                    Log.Info("Normal route path not specified, skipping..");
                }

                Thread.Sleep(5000);
            }

            if (pathArg.Parsed)
            {
                var path = Path.GetFullPath(pathArg.Value);

                if (File.Exists(path))
                {
                    DatabaseImport.ImportGravityVectors(syncRoot, path, normalRoutes);
                }
                else
                {
                    Log.Error($"The file {path} does not exist");
                    return;
                }
            }
            else
            {
                Log.Info($"Gravity vector path not specified, skipping..");
            }

            if (deviationCellsPathArg.Parsed)
            {
                var path = Path.GetFullPath(deviationCellsPathArg.Value);

                if (File.Exists(path))
                {
                    DatabaseImport.ImportDeviationCells(path);
                }
                else
                {
                    Log.Error($"The deviation map path {path} does not exist");
                    return;
                }
            }
            else
            {
                Log.Info("Deviation cell file not specified, skipping..");
            }
        }
        static void Main()
        {
            // Log4net configuration
            XmlConfigurator.Configure();

            // NHibernate configuration
            FluentConfiguration.Configure();

            var session = SessionManager.Session;

            #region Spatial Analysis Queries

            //var result = session.Query<Municipality>().OrderByDescending(m => m.Geom.Area)
            //	.Select(m => new { m.Name, m.Geom.Area })
            //	.Take(10)
            //	.ToList();

            //var result =
            //	(from m1 in session.Query<Municipality>()
            //	 select m1.Geom.Centroid)
            //	 .Take(1)
            //	 .ToList();

            //// Warning: Slow!
            //// Tip: Create an index on County.Name
            //var result =
            //	(from county in session.Query<County>()
            //	 from municipality in session.Query<Municipality>()
            //	 where municipality.Geom.Within(county.Geom.Buffer(0.000001)) && county.Name == "Sogn og Fjordane"
            //	 select municipality).ToList();

            //var result =
            //	(from c1 in session.Query<County>()
            //	 from c2 in session.Query<County>()
            //	 where c2 != c1 && c1.Id > c2.Id
            //	 orderby c1.Geom.Centroid.Distance(c2.Geom.Centroid) ascending // descending
            //	 select new { c1, c2, Distance = c1.Geom.Centroid.Distance(c2.Geom.Centroid) })
            //		.Take(5)
            //		.ToList();

            //// Warning! Slow!
            //var result =
            //	(from m1 in session.Query<Municipality>()
            //	 from m2 in session.Query<Municipality>()
            //	 where m2 != m1 && m1.Id > m2.Id
            //	 orderby m1.Geom.Centroid.Distance(m2.Geom.Centroid) descending
            //	 select new { m1, m2, Distance = m1.Geom.Centroid.Distance(m2.Geom.Centroid) })
            //	 .Take(5)
            //	 .ToList();

            //var municipality = session.Query<Municipality>().Single(m => m.Name == "Gloppen");
            //var result = session.QueryOver<County>()
            //		.WhereSpatialRestrictionOn(p => p.Geom)
            //		.Overlaps(municipality.Geom)
            //		.List();

            //// SELECT * FROM Municipality where County_id = 18;
            //// Warning! Slow if logging is enabled!
            //session.Transaction.Begin();
            //var municipalities = session.Query<Municipality>();
            //foreach (var m in municipalities)
            //{
            //	var counties = session.QueryOver<County>()
            //		.WhereSpatialRestrictionOn(p => p.Geom)
            //		.Overlaps(m.Geom)
            //		.List();

            //	if (counties.Count() > 1)
            //	{
            //		counties = counties.Where(c => c.Geom.IsValid && m.Geom.IsValid)
            //							.OrderByDescending(c => c.Geom.Intersection(m.Geom).Area)
            //								.ToList();
            //	}

            //	if (counties.Any() && m.County == null)
            //	{
            //		m.County = counties.First();
            //		m.County.Municipalities.Add(m);
            //		session.SaveOrUpdate(m);
            //	}
            //}
            //session.Transaction.Commit();

            #endregion
        }