Using SqlGeometry.MakeValid to get a counter-clockwise polygon in SQL Server Planned...

Special flights

Is there public access to the Meteor Crater in Arizona?

How to ask rejected full-time candidates to apply to teach individual courses?

Does the Mueller report show a conspiracy between Russia and the Trump Campaign?

Google .dev domain strangely redirects to https

How to change the tick of the color bar legend to black

How can I prevent/balance waiting and turtling as a response to cooldown mechanics

License to disallow distribution in closed source software, but allow exceptions made by owner?

Resize vertical bars (absolute-value symbols)

Is openssl rand command cryptographically secure?

After Sam didn't return home in the end, were he and Al still friends?

Nose gear failure in single prop aircraft: belly landing or nose-gear up landing?

How do living politicians protect their readily obtainable signatures from misuse?

what is the log of the PDF for a Normal Distribution?

Simple Http Server

If Windows 7 doesn't support WSL, then what is "Subsystem for UNIX-based Applications"?

How to write capital alpha?

Relating to the President and obstruction, were Mueller's conclusions preordained?

Printing attributes of selection in ArcPy?

Was Kant an Intuitionist about mathematical objects?

How were pictures turned from film to a big picture in a picture frame before digital scanning?

How to ternary Plot3D a function

Can an iPhone 7 be made to function as a NFC Tag?

A term for a woman complaining about things/begging in a cute/childish way



Using SqlGeometry.MakeValid to get a counter-clockwise polygon in SQL Server



Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern)
Announcing the arrival of Valued Associate #679: Cesar Manara
Unicorn Meta Zoo #1: Why another podcast?Fixing orientation in Net Topology SuiteOracle spatial - check polygon vertices counter clockwiseInserting points into SQL Server using pymssql?Detecting invalid WKT in text column in SQL ServerOrder sql server spatial geometry distance by the nearestGeoJson to Spatial Geography in sql server 2012, fix orientation of polygonWhy would FME imported data into SQL Server not being found by QGIS?How to implement Geography or geometry with spatial index implementation to find entities in the bounding box?Understanding Differences in Area Calculations between SQL Server and QGISWhen does WKT orientation matter for polygon and multipolygon in geography spatial (left/right hand rule, counter-clockwise, clockwise)T-SQL Invalid Geometry Created by Intersection





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ margin-bottom:0;
}







1















The data I've loaded from a shapefile into a geometry column in SQL Server (using NetTopologySuite) is not producing valid GeoJSON when I export it because it doesn't follow the right-hand rule.



I thought this would be easy to fix with the MakeValid() function, but it's not correcting the issue.



I tried with a simplified geometry as below:



declare @geom geometry
select @geom = geometry::STGeomFromText('POLYGON ((
0 0,
0 1,
2 1,
2 0,
0 0
))', 4326)

select @geom, @geom.IsValidDetailed()


SQL Server says it's valid (24400: Valid), so presumably that's why it's not fixing it in the MakeValid function.



What's the best way to resolve this? I've seen an option to use:
UPDATE table SET geom = geom.STUnion(geom.STStartPoint()) which works for simple polygons, but I'm not sure how well it will work for more complex geometries.










share|improve this question
















bumped to the homepage by Community 18 mins ago


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
















  • Is using ogr2ogr an acceptable option for you?

    – user30184
    Jul 16 '18 at 21:53











  • @user30184 Not really. I believe that's a command line tool, where I need it embedded in a website so a user can upload a shapefile and it gets processed (preferably using C#).

    – Sean
    Jul 17 '18 at 14:21











  • How about GDAL generally if used through C# or Python bindings? But it does feel like a heavy tool if the only problem is with ring orientations.

    – user30184
    Jul 17 '18 at 14:26













  • Yeah - I'm so close with NetTopologySuite loading the data in, there's just this one small issue, which MakeValid is supposed to fix. So I'm wondering if there's something wrong with how I'm doing it, rather than looking for a new tool.

    – Sean
    Jul 17 '18 at 18:51


















1















The data I've loaded from a shapefile into a geometry column in SQL Server (using NetTopologySuite) is not producing valid GeoJSON when I export it because it doesn't follow the right-hand rule.



I thought this would be easy to fix with the MakeValid() function, but it's not correcting the issue.



I tried with a simplified geometry as below:



declare @geom geometry
select @geom = geometry::STGeomFromText('POLYGON ((
0 0,
0 1,
2 1,
2 0,
0 0
))', 4326)

select @geom, @geom.IsValidDetailed()


SQL Server says it's valid (24400: Valid), so presumably that's why it's not fixing it in the MakeValid function.



What's the best way to resolve this? I've seen an option to use:
UPDATE table SET geom = geom.STUnion(geom.STStartPoint()) which works for simple polygons, but I'm not sure how well it will work for more complex geometries.










share|improve this question
















bumped to the homepage by Community 18 mins ago


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
















  • Is using ogr2ogr an acceptable option for you?

    – user30184
    Jul 16 '18 at 21:53











  • @user30184 Not really. I believe that's a command line tool, where I need it embedded in a website so a user can upload a shapefile and it gets processed (preferably using C#).

    – Sean
    Jul 17 '18 at 14:21











  • How about GDAL generally if used through C# or Python bindings? But it does feel like a heavy tool if the only problem is with ring orientations.

    – user30184
    Jul 17 '18 at 14:26













  • Yeah - I'm so close with NetTopologySuite loading the data in, there's just this one small issue, which MakeValid is supposed to fix. So I'm wondering if there's something wrong with how I'm doing it, rather than looking for a new tool.

    – Sean
    Jul 17 '18 at 18:51














1












1








1








The data I've loaded from a shapefile into a geometry column in SQL Server (using NetTopologySuite) is not producing valid GeoJSON when I export it because it doesn't follow the right-hand rule.



I thought this would be easy to fix with the MakeValid() function, but it's not correcting the issue.



I tried with a simplified geometry as below:



declare @geom geometry
select @geom = geometry::STGeomFromText('POLYGON ((
0 0,
0 1,
2 1,
2 0,
0 0
))', 4326)

select @geom, @geom.IsValidDetailed()


SQL Server says it's valid (24400: Valid), so presumably that's why it's not fixing it in the MakeValid function.



What's the best way to resolve this? I've seen an option to use:
UPDATE table SET geom = geom.STUnion(geom.STStartPoint()) which works for simple polygons, but I'm not sure how well it will work for more complex geometries.










share|improve this question
















The data I've loaded from a shapefile into a geometry column in SQL Server (using NetTopologySuite) is not producing valid GeoJSON when I export it because it doesn't follow the right-hand rule.



I thought this would be easy to fix with the MakeValid() function, but it's not correcting the issue.



I tried with a simplified geometry as below:



declare @geom geometry
select @geom = geometry::STGeomFromText('POLYGON ((
0 0,
0 1,
2 1,
2 0,
0 0
))', 4326)

select @geom, @geom.IsValidDetailed()


SQL Server says it's valid (24400: Valid), so presumably that's why it's not fixing it in the MakeValid function.



What's the best way to resolve this? I've seen an option to use:
UPDATE table SET geom = geom.STUnion(geom.STStartPoint()) which works for simple polygons, but I'm not sure how well it will work for more complex geometries.







geojson sql-server spatial-database geography nettopologysuite






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jul 18 '18 at 7:19







Sean

















asked Jul 16 '18 at 11:24









SeanSean

1063




1063





bumped to the homepage by Community 18 mins ago


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.







bumped to the homepage by Community 18 mins ago


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.















  • Is using ogr2ogr an acceptable option for you?

    – user30184
    Jul 16 '18 at 21:53











  • @user30184 Not really. I believe that's a command line tool, where I need it embedded in a website so a user can upload a shapefile and it gets processed (preferably using C#).

    – Sean
    Jul 17 '18 at 14:21











  • How about GDAL generally if used through C# or Python bindings? But it does feel like a heavy tool if the only problem is with ring orientations.

    – user30184
    Jul 17 '18 at 14:26













  • Yeah - I'm so close with NetTopologySuite loading the data in, there's just this one small issue, which MakeValid is supposed to fix. So I'm wondering if there's something wrong with how I'm doing it, rather than looking for a new tool.

    – Sean
    Jul 17 '18 at 18:51



















  • Is using ogr2ogr an acceptable option for you?

    – user30184
    Jul 16 '18 at 21:53











  • @user30184 Not really. I believe that's a command line tool, where I need it embedded in a website so a user can upload a shapefile and it gets processed (preferably using C#).

    – Sean
    Jul 17 '18 at 14:21











  • How about GDAL generally if used through C# or Python bindings? But it does feel like a heavy tool if the only problem is with ring orientations.

    – user30184
    Jul 17 '18 at 14:26













  • Yeah - I'm so close with NetTopologySuite loading the data in, there's just this one small issue, which MakeValid is supposed to fix. So I'm wondering if there's something wrong with how I'm doing it, rather than looking for a new tool.

    – Sean
    Jul 17 '18 at 18:51

















Is using ogr2ogr an acceptable option for you?

– user30184
Jul 16 '18 at 21:53





Is using ogr2ogr an acceptable option for you?

– user30184
Jul 16 '18 at 21:53













@user30184 Not really. I believe that's a command line tool, where I need it embedded in a website so a user can upload a shapefile and it gets processed (preferably using C#).

– Sean
Jul 17 '18 at 14:21





@user30184 Not really. I believe that's a command line tool, where I need it embedded in a website so a user can upload a shapefile and it gets processed (preferably using C#).

– Sean
Jul 17 '18 at 14:21













How about GDAL generally if used through C# or Python bindings? But it does feel like a heavy tool if the only problem is with ring orientations.

– user30184
Jul 17 '18 at 14:26







How about GDAL generally if used through C# or Python bindings? But it does feel like a heavy tool if the only problem is with ring orientations.

– user30184
Jul 17 '18 at 14:26















Yeah - I'm so close with NetTopologySuite loading the data in, there's just this one small issue, which MakeValid is supposed to fix. So I'm wondering if there's something wrong with how I'm doing it, rather than looking for a new tool.

– Sean
Jul 17 '18 at 18:51





Yeah - I'm so close with NetTopologySuite loading the data in, there's just this one small issue, which MakeValid is supposed to fix. So I'm wondering if there's something wrong with how I'm doing it, rather than looking for a new tool.

– Sean
Jul 17 '18 at 18:51










2 Answers
2






active

oldest

votes


















0














I had thought I would fix this in Sql Server using a spatial function like MakeValid, but as that didn't work, I've found a way to fix it when loading the data from the shape file, using NetTopologySuite.



I was using:



var factory = new GeometryFactory();
using (var shapeFileDataReader = new ShapefileDataReader(filePath, factory))


But simply changing the factory worked, like this:



var factory = new OgcCompliantGeometryFactory();
using (var shapeFileDataReader = new ShapefileDataReader(filePath, factory))





share|improve this answer































    0














    I've started working with NetTopologySuite, and have the same problem. I found a fix here. Simply put:



    if (!polygon.Shell.IsCCW) polygon = polygon.Reverse();


    If you have Geometries you will need to cast, and if you have MultiPolygons you will have to iterate through each of them.






    share|improve this answer
























      Your Answer








      StackExchange.ready(function() {
      var channelOptions = {
      tags: "".split(" "),
      id: "79"
      };
      initTagRenderer("".split(" "), "".split(" "), channelOptions);

      StackExchange.using("externalEditor", function() {
      // Have to fire editor after snippets, if snippets enabled
      if (StackExchange.settings.snippets.snippetsEnabled) {
      StackExchange.using("snippets", function() {
      createEditor();
      });
      }
      else {
      createEditor();
      }
      });

      function createEditor() {
      StackExchange.prepareEditor({
      heartbeatType: 'answer',
      autoActivateHeartbeat: false,
      convertImagesToLinks: false,
      noModals: true,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: null,
      bindNavPrevention: true,
      postfix: "",
      imageUploader: {
      brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
      contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
      allowUrls: true
      },
      onDemand: true,
      discardSelector: ".discard-answer"
      ,immediatelyShowMarkdownHelp:true
      });


      }
      });














      draft saved

      draft discarded


















      StackExchange.ready(
      function () {
      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fgis.stackexchange.com%2fquestions%2f289545%2fusing-sqlgeometry-makevalid-to-get-a-counter-clockwise-polygon-in-sql-server%23new-answer', 'question_page');
      }
      );

      Post as a guest















      Required, but never shown

























      2 Answers
      2






      active

      oldest

      votes








      2 Answers
      2






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      0














      I had thought I would fix this in Sql Server using a spatial function like MakeValid, but as that didn't work, I've found a way to fix it when loading the data from the shape file, using NetTopologySuite.



      I was using:



      var factory = new GeometryFactory();
      using (var shapeFileDataReader = new ShapefileDataReader(filePath, factory))


      But simply changing the factory worked, like this:



      var factory = new OgcCompliantGeometryFactory();
      using (var shapeFileDataReader = new ShapefileDataReader(filePath, factory))





      share|improve this answer




























        0














        I had thought I would fix this in Sql Server using a spatial function like MakeValid, but as that didn't work, I've found a way to fix it when loading the data from the shape file, using NetTopologySuite.



        I was using:



        var factory = new GeometryFactory();
        using (var shapeFileDataReader = new ShapefileDataReader(filePath, factory))


        But simply changing the factory worked, like this:



        var factory = new OgcCompliantGeometryFactory();
        using (var shapeFileDataReader = new ShapefileDataReader(filePath, factory))





        share|improve this answer


























          0












          0








          0







          I had thought I would fix this in Sql Server using a spatial function like MakeValid, but as that didn't work, I've found a way to fix it when loading the data from the shape file, using NetTopologySuite.



          I was using:



          var factory = new GeometryFactory();
          using (var shapeFileDataReader = new ShapefileDataReader(filePath, factory))


          But simply changing the factory worked, like this:



          var factory = new OgcCompliantGeometryFactory();
          using (var shapeFileDataReader = new ShapefileDataReader(filePath, factory))





          share|improve this answer













          I had thought I would fix this in Sql Server using a spatial function like MakeValid, but as that didn't work, I've found a way to fix it when loading the data from the shape file, using NetTopologySuite.



          I was using:



          var factory = new GeometryFactory();
          using (var shapeFileDataReader = new ShapefileDataReader(filePath, factory))


          But simply changing the factory worked, like this:



          var factory = new OgcCompliantGeometryFactory();
          using (var shapeFileDataReader = new ShapefileDataReader(filePath, factory))






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Jul 18 '18 at 7:24









          SeanSean

          1063




          1063

























              0














              I've started working with NetTopologySuite, and have the same problem. I found a fix here. Simply put:



              if (!polygon.Shell.IsCCW) polygon = polygon.Reverse();


              If you have Geometries you will need to cast, and if you have MultiPolygons you will have to iterate through each of them.






              share|improve this answer




























                0














                I've started working with NetTopologySuite, and have the same problem. I found a fix here. Simply put:



                if (!polygon.Shell.IsCCW) polygon = polygon.Reverse();


                If you have Geometries you will need to cast, and if you have MultiPolygons you will have to iterate through each of them.






                share|improve this answer


























                  0












                  0








                  0







                  I've started working with NetTopologySuite, and have the same problem. I found a fix here. Simply put:



                  if (!polygon.Shell.IsCCW) polygon = polygon.Reverse();


                  If you have Geometries you will need to cast, and if you have MultiPolygons you will have to iterate through each of them.






                  share|improve this answer













                  I've started working with NetTopologySuite, and have the same problem. I found a fix here. Simply put:



                  if (!polygon.Shell.IsCCW) polygon = polygon.Reverse();


                  If you have Geometries you will need to cast, and if you have MultiPolygons you will have to iterate through each of them.







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Aug 10 '18 at 10:49









                  SeanSean

                  1063




                  1063






























                      draft saved

                      draft discarded




















































                      Thanks for contributing an answer to Geographic Information Systems Stack Exchange!


                      • Please be sure to answer the question. Provide details and share your research!

                      But avoid



                      • Asking for help, clarification, or responding to other answers.

                      • Making statements based on opinion; back them up with references or personal experience.


                      To learn more, see our tips on writing great answers.




                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function () {
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fgis.stackexchange.com%2fquestions%2f289545%2fusing-sqlgeometry-makevalid-to-get-a-counter-clockwise-polygon-in-sql-server%23new-answer', 'question_page');
                      }
                      );

                      Post as a guest















                      Required, but never shown





















































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown

































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown







                      Popular posts from this blog

                      Щит и меч (фильм) Содержание Названия серий | Сюжет |...

                      is 'sed' thread safeWhat should someone know about using Python scripts in the shell?Nexenta bash script uses...

                      Meter-Bus Содержание Параметры шины | Стандартизация |...