<div style="display: flex; flex-wrap: wrap; white-space: pre-wrap; align-items: center; "><img height="20" width="20" style="border-radius:50%; margin-right: 4px;" decoding="async" src="https://avatars.githubusercontent.com/u/360803?s=20&v=4" /><strong>gravitystorm</strong> left a comment <a href="https://github.com/openstreetmap/openstreetmap-website/issues/6512#issuecomment-3585474641">(openstreetmap/openstreetmap-website#6512)</a></div>
<blockquote>
<p dir="auto">Are there any past instances of features that haven't been implemented, or have been implemented with workarounds, because PostGIS wasn't available?</p>
</blockquote>
<p dir="auto">For historical reasons (e.g. timing of when we moved to Postgres, widespread availability of PostGIS etc) the "nearby users" feature has been implemented using our own code. See for example <a href="https://github.com/openstreetmap/openstreetmap-website/blob/3023ef046a102226c60237634d8e11c5d6ae9a5b/app/models/user.rb#L299-L314"><code class="notranslate">User#nearby</code></a>, <a href="https://github.com/openstreetmap/openstreetmap-website/blob/3023ef046a102226c60237634d8e11c5d6ae9a5b/lib/osm.rb#L465-L467"><code class="notranslate">sql_for_distance</code></a>, <a href="https://github.com/openstreetmap/openstreetmap-website/blob/3023ef046a102226c60237634d8e11c5d6ae9a5b/lib/osm.rb#L521-L528"><code class="notranslate">sql_for_area</code></a> and the <a href="https://github.com/openstreetmap/quad_tile">QuadTile</a> library. It's a prime candidate for refactoring to use PostGIS nowadays, but we should discuss that elsewhere. As for features that haven't yet been implemented, I have lots of ideas (e.g. "notes near me") that again would be candidates for implementing with PostGIS, but again we should discuss elsewhere.</p>
<p dir="auto">Returning to the matter at hand, I believe it can be implemented using PostGIS, without adding any additional columns to the nodes/ways/relations or changesets tables. I would attempt an implementation as follows:</p>
<ul dir="auto">
<li>create a "zones" table (name tbd, I'm just using a distinctive one here to help illustration) with usual attributes, created_by etc and a PostGIS geometry column</li>
<li>Have a form for creating zones, with something like <a href="https://terradraw.io/" rel="nofollow">https://terradraw.io/</a> to create the geometry attribute</li>
<li>Hook into the <a href="https://github.com/openstreetmap/openstreetmap-website/blob/3023ef046a102226c60237634d8e11c5d6ae9a5b/app/models/changeset.rb#L145-L153"><code class="notranslate">Changeset#update_bbox</code></a> method, and throw an error if the changeset overlaps any zone</li>
<li>This can be detected by creating a postgis bbox for the changeset at query-time, and relying on the PostGIS indexes and intersection tests to efficiently check for overlapping zones, e.g. (pseudo-query) <code class="notranslate">select * from zones where ST_Intersects(ST_MakeEnvelope(#{changeset.min_lon}, #{...}, ...), zones.geometry)</code> or similar</li>
</ul>
<p dir="auto">As for whether we should use PostGIS or continue writing/using our own spatial code, I think PostGIS is my preferred choice for this. It moves all the heavy lifting (e.g. 2D-indexes, intersection testing) to a well-maintained library, and if we only need ~1 line of SQL to detect the overlaps, it's much easier to implement both here and in cgimap with much duplication.</p>
<p dir="auto">There's a few details to be worked out (e.g. exact type of the geometry column, should zones auto-expire like UserBlocks etc) but the spatial stuff is important to nail down first.</p>
<p style="font-size:small;-webkit-text-size-adjust:none;color:#666;">—<br />Reply to this email directly, <a href="https://github.com/openstreetmap/openstreetmap-website/issues/6512#issuecomment-3585474641">view it on GitHub</a>, or <a href="https://github.com/notifications/unsubscribe-auth/AAK2OLMLUH4NN3TJ4LHU72T363RLJAVCNFSM6AAAAACLVP5GA6VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZTKOBVGQ3TINRUGE">unsubscribe</a>.<br />You are receiving this because you are subscribed to this thread.<img src="https://github.com/notifications/beacon/AAK2OLO5CRJJT6WE7WZXV3L363RLJA5CNFSM6AAAAACLVP5GA6WGG33NNVSW45C7OR4XAZNMJFZXG5LFINXW23LFNZ2KUY3PNVWWK3TUL5UWJTWVWYAFC.gif" height="1" width="1" alt="" /><span style="color: transparent; font-size: 0; display: none; visibility: hidden; overflow: hidden; opacity: 0; width: 0; height: 0; max-width: 0; max-height: 0; mso-hide: all">Message ID: <span><openstreetmap/openstreetmap-website/issues/6512/3585474641</span><span>@</span><span>github</span><span>.</span><span>com></span></span></p>
<script type="application/ld+json">[
{
"@context": "http://schema.org",
"@type": "EmailMessage",
"potentialAction": {
"@type": "ViewAction",
"target": "https://github.com/openstreetmap/openstreetmap-website/issues/6512#issuecomment-3585474641",
"url": "https://github.com/openstreetmap/openstreetmap-website/issues/6512#issuecomment-3585474641",
"name": "View Issue"
},
"description": "View this Issue on GitHub",
"publisher": {
"@type": "Organization",
"name": "GitHub",
"url": "https://github.com"
}
}
]</script>