//**********************************************************************
        //							pj_c_findgrid()
        //**********************************************************************
        public static PJ_GRIDINFO pj_gc_findgrid(projCtx ctx, PJ_GridCatalog catalog, bool after, LP location, double date, ref PJ_Region optimal_region, ref double grid_date)
        {
            for (int i = 0; i < catalog.entries.Count; i++)
            {
                PJ_GridCatalog.Entry entry = catalog.entries[i];

                if ((after && entry.date < date) || (!after && entry.date > date))
                {
                    continue;
                }

                if (location.lam < entry.region.ll_long || location.lam > entry.region.ur_long ||
                    location.phi < entry.region.ll_lat || location.phi > entry.region.ur_lat)
                {
                    continue;
                }

                if (entry.available == -1)
                {
                    continue;
                }

                grid_date = entry.date;

                if (entry.gridinfo == null)
                {
                    int           grid_count;
                    PJ_GRIDINFO[] gridlist = pj_gridlist_from_nadgrids(ctx, entry.definition, out grid_count);
                    if (grid_count == 1)
                    {
                        entry.gridinfo = gridlist[0];
                    }
                }

                return(entry.gridinfo);
            }

            grid_date      = 0.0;
            optimal_region = new PJ_Region();
            return(null);
        }
Exemple #2
0
        //***********************************************************************
        //							pj_gc_readcatalog()
        //
        //		Read a grid catalog from a .csv file.
        //***********************************************************************
        public static PJ_GridCatalog pj_gc_readcatalog(projCtx ctx, string catalog_name)
        {
            FileStream fs = Proj.pj_open_lib(ctx, catalog_name, FileAccess.Read);

            if (fs == null)
            {
                return(null);
            }

            using (StreamReader fid = new StreamReader(fs))
            {
                // discard title line
                fid.ReadLine();

                PJ_GridCatalog catalog;

                try
                {
                    catalog = new PJ_GridCatalog();
                }
                catch
                {
                    return(null);
                }

                catalog.catalog_name = catalog_name;

                catalog.entries = new List <PJ_GridCatalog.Entry>();

                PJ_GridCatalog.Entry entry;
                while (!pj_gc_readentry(ctx, fid, out entry))
                {
                    catalog.entries.Add(entry);
                }

                fid.Close();

                return(catalog);
            }
        }
        //**********************************************************************
        //						pj_gc_findcatalog()
        //**********************************************************************
        public static PJ_GridCatalog pj_gc_findcatalog(projCtx ctx, string name)
        {
            lock (gridlock)
            {
                for (int i = 0; i < grid_catalog_list.Count; i++)
                {
                    if (grid_catalog_list[i].catalog_name == name)
                    {
                        return(grid_catalog_list[i]);
                    }
                }
            }

            PJ_GridCatalog catalog = pj_gc_readcatalog(ctx, name);

            if (catalog == null)
            {
                return(null);
            }

            lock (gridlock) grid_catalog_list.Add(catalog);

            return(catalog);
        }
Exemple #4
0
        //**********************************************************************
        //                            pj_c_findgrid()
        //**********************************************************************
        public static PJ_GRIDINFO pj_gc_findgrid(projCtx ctx, PJ_GridCatalog catalog, bool after, LP location, double date, ref PJ_Region optimal_region, ref double grid_date)
        {
            for(int i=0; i<catalog.entries.Count; i++)
            {
                PJ_GridCatalog.Entry entry=catalog.entries[i];

                if((after&&entry.date<date)||(!after&&entry.date>date)) continue;

                if(location.lam<entry.region.ll_long||location.lam>entry.region.ur_long||
                    location.phi<entry.region.ll_lat||location.phi>entry.region.ur_lat) continue;

                if(entry.available==-1)
                    continue;

                grid_date=entry.date;

                if(entry.gridinfo==null)
                {
                    int grid_count;
                    PJ_GRIDINFO[] gridlist=pj_gridlist_from_nadgrids(ctx, entry.definition, out grid_count);
                    if(grid_count==1) entry.gridinfo=gridlist[0];
                }

                return entry.gridinfo;
            }

            grid_date=0.0;
            optimal_region=new PJ_Region();
            return null;
        }