Discussion:
[mapguide-users] Help with Spatial Contexts
gom
2017-03-06 16:08:39 UTC
Permalink
I asked an earlier question about PostGis and spatial context issues. I'm
not sure it was a very clear question so I decided it might be better to try
and ask a more general question to see if I am making a more fundamental
mistake in my approach to authoring resources.

I need some help understanding Data Sources, Layers and Spatial Contexts.
Specifically how they are detected, defined in data sources and then
assigned to layers.

Should I always have a separate data source for every layer?
Should I have a separate data source for every Spatial Context in a
database?
How does a layer get assigned a Spatial Context?
Can I specify what Spatial Context a layer should use?

Thanks



--
View this message in context: http://osgeo-org.1560.x6.nabble.com/Help-with-Spatial-Contexts-tp5310988.html
Sent from the MapGuide Users mailing list archive at Nabble.com.
Jackie Ng
2017-03-07 10:47:26 UTC
Permalink
The logical model goes like this:

A Feature Source
- Has 1..n spatial contexts
- Each spatial context is uniquely named
- Has 1..n feature classes
- Each feature class has a designated logical geometry property
- That geometry property has a spatial context association (to an
existing name spatial context in the Feature Source)

Thus a layer's spatial context is the spatial context of the chosen geometry
property of the feature class it is referencing. You don't assign a spatial
context to a layer, you assign a feature class/geometry and the layer picks
up the referenced spatial context from that.

Now seeing you are talking about PostGIS in your other un-answered post, let
me try to have a reasonable guess at how the FDO provider translates the
PostGIS database into this logical model

A Feature Source (A connection to a PostGIS database)
- Has 1..n spatial contexts
- [PostGIS Provider] It most likely infers this list from the
spatial_ref_sys and geometry_columns metadata tables
- Has 1..n feature classes
- [PostGIS Provider] Any table that has a geometry/geography column
- Each feature class has a designated logical geometry property
- [PostGIS Provider] It probably either takes the first
geometry/geography column or whatever is specified in geometry_columns
- That geometry property has a spatial context of the chosen geometry
property of the feature class it is referencing.
- [PostGIS Provider] It probably either looks up geometry_columns or
ST_SRID()'s the geometry/geography column so it knows what spatial_ref_sys
table entry you are referring to.

Now if you're wondering what is the purpose of a spatial context, it is
primarily to determine the coordinate system of the originating layer.
MapGuide uses spatial context information to determine if layers need
on-the-fly feature re-projection when rendering maps.

Hope that helps.

- Jackie



--
View this message in context: http://osgeo-org.1560.x6.nabble.com/Help-with-Spatial-Contexts-tp5310988p5311169.html
Sent from the MapGuide Users mailing list archive at Nabble.com.
gom
2017-03-09 15:23:39 UTC
Permalink
Thanks for the thorough answer. That does match what my understanding has
been. My question arose because I added a data table to PostGIS recently.
In the Maestro Preview of that data source, the table showed sc_3 as the
spatial context of the table. The layer showed sc_2 as its selected spatial
context. SC_3 was a 10TM zone and sc_2 was a UTM11 zone. The data shift,
when adding the layer to the map, was equal to the difference in the two UTM
zone definitions.

I tried to refresh the spatial contexts list.
I dropped and recreated the layer.
The problem never went away.

I have not tried to re-create the data source as I have an application with
quite a few layers using this data source. I have quite a lot of tables in
the database as well as about 9 -10 different spatial contexts. Tables have
been added and dropped over time. Maybe I need to vacuum the database or do
some other maintenance to clean it up.

I will try to recreate the data source to see if there is anything related
to that.

Thanks again.



--
View this message in context: http://osgeo-org.1560.x6.nabble.com/Help-with-Spatial-Contexts-tp5310988p5311605.html
Sent from the MapGuide Users mailing list archive at Nabble.com.
Jackie Ng
2017-03-09 21:53:42 UTC
Permalink
I know for SQL Server, the provider may create a f_scinfo table to store
intermediate data for spatial contexts. Since the PostgreSQL provider is
built on the same core, it may be creating a f_scinfo table for this purpose
as well.

Does your database have this table?

- Jackie



--
View this message in context: http://osgeo-org.1560.x6.nabble.com/Help-with-Spatial-Contexts-tp5310988p5311686.html
Sent from the MapGuide Users mailing list archive at Nabble.com.
Flipper
2017-03-09 22:02:43 UTC
Permalink
Where do the sc_1, sc_2, etc come from when you list Coordinate Systems
Overrides for SQL server in Maestro? Is this just an autonumber internally
to Maestro or is this stored somewhere in SQL?



--
View this message in context: http://osgeo-org.1560.x6.nabble.com/Help-with-Spatial-Contexts-tp5310988p5311687.html
Sent from the MapGuide Users mailing list archive at Nabble.com.
Jackie Ng
2017-03-09 23:18:01 UTC
Permalink
Maestro does no auto-numbering. Definitely comes from the FDO provider.

- Jackie



--
View this message in context: http://osgeo-org.1560.x6.nabble.com/Help-with-Spatial-Contexts-tp5310988p5311692.html
Sent from the MapGuide Users mailing list archive at Nabble.com.
Jackie Ng
2017-03-09 23:21:07 UTC
Permalink
Since the PostgreSQL provider is built on the same GenericRdbms core as the
other relational providers, you should still be able to activate tracing via
the FDO_TRACE_FILE environment variable and have a look at the SQL
statements the provider is executing to get its spatial contexts

http://themapguyde.blogspot.com.au/2013/01/mapguide-tidbits-fdo-rdbms-provider.html

- Jackie



--
View this message in context: http://osgeo-org.1560.x6.nabble.com/Help-with-Spatial-Contexts-tp5310988p5311693.html
Sent from the MapGuide Users mailing list archive at Nabble.com.
gom
2017-03-10 14:05:21 UTC
Permalink
I'll try this.

Thanks



--
View this message in context: http://osgeo-org.1560.x6.nabble.com/Help-with-Spatial-Contexts-tp5310988p5311753.html
Sent from the MapGuide Users mailing list archive at Nabble.com.
Bernhard Maehler
2017-03-10 20:10:52 UTC
Permalink
I am using PostgreSQL 9.6.2 with PostGIS 2.3.2 and AIMS 2017.
As Jackie has mentioned before, I can confirm that the PostgreSQL Provider
uses the f_scinfo table to obtain the name of the spatial context.
However this table has no data and it is not necessary to create it as it
only provides the names for the spatial context.

Further explanations (example):

Your PostgreGIS database has three tables: table_a, table_b and table_c.
Each table has a different spatial context (EPSG code):
- table_a uses EPSG code 3400 -- NAD83 / Alberta 10-TM (Forest)
- table_b uses EPSG code 4269 -- NAD83
- table_c uses EPSG code 4326 -- WGS 84
Once you have crated a new feature source (= data source or connection to
your PostGIS database with Maestro) the spatial contexts are named like sc_1
(for EPSG:3400), sc_2 (for EPSG:4269), sc_3 (for EPSG:4326).
Once you have created your layers from your new data source (e. g. layer_a
for table_a, layer_b for table_b, layer_c for table_c) the assigned spatial
contexts for the layers are:
- sc_1 for layer_a (= EPSG:3400)
- sc_2 for layer_b (= EPSG:4269)
- sc_3 for layer_c (= EPSG:4326)
So each layer uses its own spatial context which is automatically assigned
by your feature source.

To come back to your question:
Should I always have a separate data source for every layer?
- No
Should I have a separate data source for every Spatial Context in a
database?
- No
How does a layer get assigned a Spatial Context?
- From the spatial context of the assigned PostGIS table or the view
public.geometry_columns
Can I specify what Spatial Context a layer should use?
- Not directly, with Maestro you can overwrite the spatial context of your
data source but this affects all layers that use the same spatial context. A
better way is to transform the spatial context of your table (layer) with
PostGIS functions.

If you want clear names for your spatial context, you can use the following
SQL script to create the table f_scinfo.
The PostgreSQL Provider obtains the names of the spatial context from the
columns of this table, so instead of "sc_1" the name will be "EPSG_3400".
For each spatial context (EPSG code) of your database you have to create a
new column.


-- Table: public.f_scinfo
 
-- DROP TABLE public.f_scinfo;
 
CREATE TABLE public.f_scinfo
(
  f_scinfo_id bigint NOT NULL,
  "EPSG_3400" geometry(Geometry,3400),
  "EPSG_4269" geometry(Geometry,4269),
  "EPSG_4326" geometry(Geometry,4326),
  CONSTRAINT pk_f_scinfo PRIMARY KEY (f_scinfo_id)
)
WITH (
  OIDS=FALSE
);
 
-- Spatial index: public.f_scinfo_epsg_3400_si
 
-- DROP INDEX public.f_scinfo_epsg_3400_si;
 
CREATE INDEX f_scinfo_epsg_3400_si
  ON public.f_scinfo
  USING gist
  ("EPSG_3400");
 
-- Spatial index: public.f_scinfo_epsg_4326_si
 
-- DROP INDEX public.f_scinfo_epsg_4326_si;
 
CREATE INDEX f_scinfo_epsg_4269_si
  ON public.f_scinfo
  USING gist
  ("EPSG_4269");
 
-- Spatial index: public.f_scinfo_epsg_4326_si
 
-- DROP INDEX public.f_scinfo_epsg_4326_si;
 
CREATE INDEX f_scinfo_epsg_4326_si
  ON public.f_scinfo
  USING gist
  ("EPSG_4326");

Output in Maestro:

<Loading Image...>

- Bernhard






--
View this message in context: http://osgeo-org.1560.x6.nabble.com/Help-with-Spatial-Contexts-tp5310988p5311809.html
Sent from the MapGuide Users mailing list archive at Nabble.com.
gom
2017-03-13 14:42:06 UTC
Permalink
Thanks for all the answers. I have a much clearer picture of what I should
be doing. I see my database has no f_scinfo table but I do understand that
this is optional. Needed only if I want a more clearly named spatial
context as opposed to sc_1, sc_2 etc.



--
View this message in context: http://osgeo-org.1560.x6.nabble.com/Help-with-Spatial-Contexts-tp5310988p5312077.html
Sent from the MapGuide Users mailing list archive at Nabble.com.
gom
2017-04-17 19:52:08 UTC
Permalink
I know this is a few weeks old but as I tried to add two new layers to a map
I have struggled with Spatial Contexts again.

I have captured some images from my data source and layer definition in
order to show that the layer seems to choose the wrong Spatial Context. I
have created and recreated the data source and layer, reloaded the spatial
contexts and tried to redefine everything but to no avail. UTM 10 is my
data Spatial Context and it is shown correctly in the data source definition
and preview. However the layer always shows as being WGS84. This is a
valid context in my data source definition but it does not apply to this
table. The layer will not draw in the map. (The map is a 10TM projection).
Other layers that are UTM13, LL83 and WGS84.

I just can't figure out why the layer uses WGS84 instead of UTM10. Any
ideas? Can I provide any other information to help sort this out?

Thanks

*Datasource Preview shows sc_7 for this table:*
<Loading Image...>

*sc_7 as defined in datasource:*
<Loading Image...>

*layer datasource:*
<Loading Image...>

*layer preview:*
<Loading Image...>



--
View this message in context: http://osgeo-org.1560.x6.nabble.com/Help-with-Spatial-Contexts-tp5310988p5317502.html
Sent from the MapGuide Users mailing list archive at Nabble.com.

Loading...