On 14 June 2010 06:09, Rui Daniro <span dir="ltr">&lt;<a href="mailto:ruidaniro@hotmail.co.uk" target="_blank">ruidaniro@hotmail.co.uk</a>&gt;</span> wrote:<br><div class="gmail_quote"><blockquote class="gmail_quote" style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0.8ex;border-left-width:1px;border-left-color:rgb(204, 204, 204);border-left-style:solid;padding-left:1ex">


<br>Hi,<br>Thanks in advance for your time.<br>I am a begginer with Postgis and I am trying to create a table with multiple<br>geometries using Postgis,but I am struggling to find the workaround, can you<br>give me some hints on how to do this or guide me somewhere I can find any<br>


help?<br></blockquote><div><br></div><div>Hi Rui,</div><div><br></div><div>I just had to use the workaround in my office for AutoCAD Map3D 2011, so I&#39;ll show you my example solution. However, this is a read-only solution:</div>

<div><br></div><div><div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace">CREATE TABLE public.structure</font></div><div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace">(</font></div>

<div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace">  gid serial NOT NULL,</font></div><div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace">  unref geometry,</font></div><div>

<font class="Apple-style-span" face="&#39;courier new&#39;, monospace">  georef geometry,</font></div><div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace">  name1 character varying(100),</font></div>

<div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace">  name2 character varying(100),</font></div><div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace">  CONSTRAINT structure_pkey PRIMARY KEY (gid),</font></div>

<div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace">  CONSTRAINT enforce_dims_georef CHECK (ndims(georef) = 2),</font></div><div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace">  CONSTRAINT enforce_dims_unref CHECK (ndims(unref) = 2),</font></div>

<div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace">  CONSTRAINT enforce_geotype_georef CHECK (geometrytype(georef) = &#39;MULTIPOLYGON&#39;::text OR georef IS NULL),</font></div><div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace">  CONSTRAINT enforce_geotype_unref CHECK (geometrytype(unref) = &#39;MULTIPOLYGON&#39;::text OR unref IS NULL),</font></div>

<div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace">  CONSTRAINT enforce_srid_georef CHECK (srid(georef) = 4326),</font></div><div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace">  CONSTRAINT enforce_srid_unref CHECK (srid(unref) = (-1)),</font></div>

<div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace">  CONSTRAINT enforce_valid_georef CHECK (st_isvalid(georef)),</font></div><div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace">  CONSTRAINT enforce_valid_unref CHECK (st_isvalid(unref))</font></div>

<div><span class="Apple-style-span" style="font-family: &#39;courier new&#39;, monospace; ">);</span></div><div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace"><br></font></div><div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace">CREATE INDEX structure_georef_idx</font></div>

<div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace">  ON public.structure </font><font class="Apple-style-span" face="&#39;courier new&#39;, monospace">USING gist</font><span class="Apple-style-span" style="font-family: &#39;courier new&#39;, monospace; ">(georef);</span></div>

<div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace"><br></font></div><div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace">CREATE OR REPLACE VIEW public.structure_georef AS </font></div>

<div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace"> SELECT structure.gid, structure.georef, structure.name1, structure.name2</font></div><div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace">   FROM public.structure;</font></div>

</div><div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace"><br></font></div><div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace">-- Update metadata:</font></div><div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace"><div>

INSERT INTO geometry_columns(f_table_catalog, f_table_schema, f_table_name, f_geometry_column, coord_dimension, srid, &quot;type&quot;)</div><div>VALUES (&#39;&#39;,&#39;public&#39;,&#39;structure&#39;,&#39;unref&#39;,&#39;2&#39;,&#39;-1&#39;,&#39;MULTIPOLYGON&#39;),</div>

<div>(&#39;&#39;,&#39;public&#39;,&#39;structure&#39;,&#39;georef&#39;,&#39;2&#39;,&#39;4326&#39;,&#39;MULTIPOLYGON&#39;),</div><div>(&#39;&#39;,&#39;public&#39;,&#39;structure_georef&#39;,&#39;georef&#39;,&#39;2&#39;,&#39;4326&#39;,&#39;MULTIPOLYGON&#39;);</div>

<div><br></div></font></div><div><br></div><div>Although &quot;georef&quot; is the only column with a spatial index, it is not selected by AutoCAD, rather it picks the un-indexed &quot;unref&quot; column, which appears before &quot;georef&quot;. So, that&#39;s why I made the view &quot;structure_georef&quot; to explicitly select that column. Load up this in AutoCAD to view the data. Brent, is this a bug? Why isn&#39;t &quot;georef&quot; picked?</div>

<div><br></div><div>I have to test INSERT/UPDATE/DELETE rules on the view to see if I can make the view act more like a table, because this example makes read-only view. See <a href="http://www.postgresql.org/docs/8.4/interactive/rules-update.html">http://www.postgresql.org/docs/8.4/interactive/rules-update.html</a></div>

<div><br></div><div>Sorry it isn&#39;t for &quot;the beginner,&quot; but hope it helps.</div><div><br></div><div>-Mike</div></div>