# PostgreSql FeatureLayer

**URL:** <https://community.thinkgeo.com/t/postgresql-featurelayer/5511>\
**Category:** WebForms\
**Created:** [October 9, 2010, 4:35am UTC](https://community.thinkgeo.com/t/postgresql-featurelayer/5511 "2010-10-09T04:35:17Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Paolo](https://community.thinkgeo.com/letter_avatar_proxy/v4/letter/p/6f9a4e/32.png) [@Paolo](https://community.thinkgeo.com/u/Paolo)\
**Post date:** [October 9, 2010, 4:35am UTC](https://community.thinkgeo.com/t/postgresql-featurelayer/5511/1 "2010-10-09T04:35:17Z")

</div>

&nbsp;Hi,

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;I&nbsp;have&nbsp;setup&nbsp;a&nbsp;map&nbsp;with&nbsp;a&nbsp;PostgreSqlFeatureLayer&nbsp;as&nbsp;the&nbsp;code&nbsp;below,&nbsp;but&nbsp;on&nbsp;clicking&nbsp;a&nbsp;station&nbsp;point&nbsp;no&nbsp;one&nbsp;feature&nbsp;is&nbsp;found.&nbsp;am&nbsp;I&nbsp;doing&nbsp;something&nbsp;wrong&nbsp;?

Thanks&nbsp;in&nbsp;advance

Paolo&nbsp;Saudin

&nbsp;

``

`         protected void Page_Load(object sender, EventArgs e)`

`

        {

            if (!Page.IsPostBack)

            {

 

                /*

                 * map properties

                 */

                Map1.MapBackground.BackgroundBrush = new GeoSolidBrush(GeoColor.FromHtml("#E5E3DF"));

                Map1.MapUnit = GeographyUnit.Meter;

 

                /*

                 * map tools

                 */

                Map1.MapTools.OverlaySwitcher.Enabled = true;

                Map1.MapTools.OverlaySwitcher.BackgroundColor = GeoColor.StandardColors.Lavender;

                Map1.MapTools.OverlaySwitcher.BaseOverlayTitle = "Mappa";

                Map1.MapTools.OverlaySwitcher.DynamicOverlayTitle = "Layers";

                Map1.MapTools.PanZoomBar.Enabled = true;

                Map1.MapTools.PanZoomBar.IsGlobeButtonEnabled = false;

                Map1.MapTools.MouseCoordinate.Enabled = true;

                Map1.MapTools.MouseMapTool.Enabled = true;

                Map1.MapTools.ScaleLine.Enabled = true;

 

                /*

                 * main layer

                 */

                GoogleOverlay googleOverlay = new GoogleOverlay("GoogleOverlay");

                googleOverlay.JavaScriptLibraryUri = new Uri(ConfigurationManager.AppSettings["GoogleUri"]);

                googleOverlay.GoogleMapType = GoogleMapType.Normal;

 

                /*

                 * stations layer

                 */

                PostgreSqlFeatureLayer stationsLayer = null;

                string connectString = "Server=localhost;User Id=postgres;Password=postgres;DataBase=rete_llpp;";

                stationsLayer = new PostgreSqlFeatureLayer(connectString, "metadati_postgis", "st_id", 23032, "metadata", "geometria");

                stationsLayer.Name = "Stations Layer";

                stationsLayer.ZoomLevelSet.ZoomLevel01.DefaultPointStyle = new PointStyle(PointSymbolType.Circle, new GeoSolidBrush(GeoColor.SimpleColors.DarkBlue), 9);

                stationsLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level12;

 

                /*

                 * manage the projection

                 */

                Proj4Projection proj4 = new Proj4Projection();

                proj4.InternalProjectionParametersString = Proj4Projection.GetEpsgParametersString(23032);

                proj4.ExternalProjectionParametersString = Proj4Projection.GetGoogleMapParametersString();

                

                /*

                 * create overlays

                 */

                // stations

                LayerOverlay stationsOverlay = null;

                if (stationsLayer != null)

                {

                    stationsOverlay = new LayerOverlay("Stations Overlay", false, TileType.SingleTile); // , false, TileType.SingleTile

                    stationsOverlay.Layers.Add("Stations Layer", stationsLayer);

                    stationsOverlay.TransitionEffect = TransitionEffect.None;

                    stationsLayer.FeatureSource.Projection = proj4;

                }

 

                /*

                 * finally add all the layers

                 */

                if (googleOverlay != null) { Map1.CustomOverlays.Add(googleOverlay); }

                if (stationsOverlay != null) { Map1.CustomOverlays.Add(stationsOverlay); }

 

                /*

                 * sets the extents

                 */

                stationsLayer.Open();

                Map1.CurrentExtent = stationsLayer.GetBoundingBox();

                stationsLayer.Close();

   

            }

        }

 

        protected void Map1_Click(object sender, MapClickedEventArgs e)

        {

            LayerOverlay staticOverlay = (LayerOverlay)Map1.CustomOverlays["Stations Overlay"];

 

            PostgreSqlFeatureLayer shapeFileLayer = (PostgreSqlFeatureLayer)(staticOverlay.Layers[0]);

 

            PointShape pointShape = (PointShape)e.Position;

            string connectString = "Server=localhost;User Id=postgres;Password=postgres;DataBase=rete_llpp;";

            shapeFileLayer.ConnectionString = connectString;

            shapeFileLayer.Open();

            Collection<Feature> selectedFeatures = shapeFileLayer.QueryTools.GetFeaturesContaining(pointShape, ReturningColumnsType.AllColumns);

            shapeFileLayer.Close();

 

            CloudPopup popup;

            if (Map1.Popups.Count == 0)

            {

                popup = new CloudPopup("Popup", e.Position, string.Empty, 260, 60);

                popup.IsVisible = true;

                Map1.Popups.Add(popup);

            }

            else

            {

                popup = (CloudPopup)Map1.Popups["Popup"];

                popup.Position = e.Position;

            }

 

            popup.ContentHtml = GetPopupContent(selectedFeatures);

        }

 

        private static string GetPopupContent(Collection<Feature> features)

        {

            string content;

            if (features.Count > 0)

            {

                StringBuilder message = new StringBuilder();

                message.AppendFormat("
Station Name : {0}", features[0].ColumnValues["stazione"].Trim());
                string messageInPopup = String.Format("{0}", message.ToString());

                content = messageInPopup;

            }

            else

            {

                content = @"Clicca su di un punto per ottenere le informazioni.";

            }

            return content;

        }
 `  

&nbsp;

---

<div class="post-metadata">

**Author:** ![Johnny](https://community.thinkgeo.com/user_avatar/community.thinkgeo.com/johnny/32/19044_2.png) [@Johnny](https://community.thinkgeo.com/u/Johnny)\
**Post date:** [October 12, 2010, 3:09am UTC](https://community.thinkgeo.com/t/postgresql-featurelayer/5511/2 "2010-10-12T03:09:00Z")

</div>

&nbsp;

Paolo,  
I&nbsp;think&nbsp;the&nbsp;problem&nbsp;comes&nbsp;from&nbsp;the&nbsp;line&nbsp;of&nbsp;code&nbsp;“Collection&nbsp;selectedFeatures&nbsp;=&nbsp;shapeFileLayer.QueryTools.GetFeaturesContaining(pointShape,&nbsp;ReturningColumnsType.AllColumns);”.&nbsp;When&nbsp;we&nbsp;click&nbsp;on&nbsp;the&nbsp;map,&nbsp;the&nbsp;application&nbsp;just&nbsp;can&nbsp;get&nbsp;a&nbsp;point&nbsp;where&nbsp;we&nbsp;click,&nbsp;it&nbsp;should&nbsp;a&nbsp;coordinate&nbsp;(X,&nbsp;Y),&nbsp;but&nbsp;the&nbsp;stations&nbsp;also&nbsp;are&nbsp;presented&nbsp;by&nbsp;(X,&nbsp;Y)&nbsp;coordinates.&nbsp;I&nbsp;think&nbsp;it’s&nbsp;hard&nbsp;to&nbsp;say&nbsp;one&nbsp;point&nbsp;contains&nbsp;another&nbsp;point&nbsp;without&nbsp;any&nbsp;buffer,&nbsp;right?&nbsp;So&nbsp;please&nbsp;use&nbsp;“shapeFileLayer.QueryTools.GetFeaturesNearestTo”&nbsp;instead.  
&nbsp;  
Thanks,  
&nbsp;  
Johnny

---

<div class="post-metadata">

**Author:** ![Paolo](https://community.thinkgeo.com/letter_avatar_proxy/v4/letter/p/6f9a4e/32.png) [@Paolo](https://community.thinkgeo.com/u/Paolo)\
**Post date:** [October 12, 2010, 2:13pm UTC](https://community.thinkgeo.com/t/postgresql-featurelayer/5511/3 "2010-10-12T14:13:25Z")

</div>

Hi&nbsp;Johnny,&nbsp;  
&nbsp;&nbsp;  
&nbsp;&nbsp;&nbsp;it&nbsp;works&nbsp;like&nbsp;a&nbsp;charm&nbsp;!!&nbsp;I’am&nbsp;really&nbsp;new&nbsp;to&nbsp;gis&nbsp;stuff&nbsp;…&nbsp;  
&nbsp;&nbsp;&nbsp;&nbsp;  
&nbsp;Thank&nbsp;you&nbsp;very&nbsp;much&nbsp;!!&nbsp;  
&nbsp;paolo

---

<div class="post-metadata">

**Author:** ![Johnny](https://community.thinkgeo.com/user_avatar/community.thinkgeo.com/johnny/32/19044_2.png) [@Johnny](https://community.thinkgeo.com/u/Johnny)\
**Post date:** [October 13, 2010, 7:31am UTC](https://community.thinkgeo.com/t/postgresql-featurelayer/5511/4 "2010-10-13T07:31:57Z")

</div>

Hi&nbsp;Paolo,&nbsp;  
&nbsp;&nbsp;  
&nbsp;That’s&nbsp;great.&nbsp;Any&nbsp;questions&nbsp;please&nbsp;let&nbsp;us&nbsp;know.&nbsp;  
&nbsp;&nbsp;  
&nbsp;Thanks,&nbsp;  
&nbsp;&nbsp;  
&nbsp;Johnny
