Create a new point layer from centroids of polygon laying retaining information from polygon layer

2,341 views
Skip to first unread message

mark909

unread,
Jan 20, 2011, 2:15:30 PM1/20/11
to MapInfo-L
Hello,

I would like to create a new point layer from centroids of polygon
laying retaining the information from polygon layer.

I tried updating the polygon table using centroid_x and centroid_y
update columns and using that to create new points but must be going
the wrong way about it.

Any help greatly appreciated!

Thanls

Bill Thoen

unread,
Jan 20, 2011, 3:14:04 PM1/20/11
to mapi...@googlegroups.com
Try using CentroidX( obj ) and CentroidY( obj ) instead. and don't
forget to first set the CoordSys that you want your coordinates to use.
If you want to use the coordsys that your table is using, then enter in
the MapBasic window:

Set CoordSys Table myTable

or you can read about coordinate systems and just spell it out longhand
as in

Set CoordSys Earth Projection 3, 104, 7, 105.142562, -45.979588, ... etc.

Otherwise you'll get Lat/Longs in the default coordinate system, which
assumes a fairly simple model of earth as a sphere, and I think sans datum.

--

*Bill Thoen*
GISnet - www.gisnet.com <http://www.gisnet.com/>
1401 Walnut St., Suite C
Boulder, CO 80302
303-786-9961 tel
303-443-4856 fax
bth...@gisnet.com

Peter Horsbøll Møller

unread,
Jan 20, 2011, 5:26:25 PM1/20/11
to mapi...@googlegroups.com
No reason to take the trip around CentroidX() and CentroidY().
Just simply use the Centroid() function to get a point

Peter Horsbøll Møller
Pitney Bowes Business Insight - MapInfo


2011/1/20 Bill Thoen <bth...@gisnet.com>


--
You received this message because you are subscribed to the Google Groups "MapInfo-L" group.To post a message to this group, send email to mapi...@googlegroups.com
To unsubscribe from this group, go to:
http://groups.google.com/group/mapinfo-l/subscribe?hl=en
For more options, information and links to MapInfo resources (searching
archives, feature requests, to visit our Wiki, visit the Welcome page at
http://groups.google.com/group/mapinfo-l?hl=en

David Reid

unread,
Jan 20, 2011, 6:01:56 PM1/20/11
to mapi...@googlegroups.com
To create a "new layer" presuming you're objective is to create a complete
new MI Table, simply make a copy of the polygon table "layer" you wish to
make point objects from, or if the polygons are mixed with other type
objects, you'd naturally have to select them either manually or with a
query, then save the new table that way.

Once you've saved your new table which consists of only polygons you wish to
create points from:

1) open this new table and make it editable
2) select "All" the polygon objects within this new table
3) open the Mapbasic window
4) type or paste the following script snippet into the Mapbasic Window and
hit enter.
Update Selection Set OBJ = Centroid(OBJ) 'Convert region object to a point
object
5) Save the table and revel in the joy of having your newly created points
table based on the centroid of the original polygons.

Your coordinate system and all table data will be the same as the original
polygon table you first created this new table from.


HTH
David Reid
Just another antiquated/seditious 9-1-1 mapping guy not running ESRI
products

Hello,

Any help greatly appreciated!

Thanls

--

Bill Thoen

unread,
Jan 20, 2011, 6:32:48 PM1/20/11
to mapi...@googlegroups.com
Peter Horsbøll Møller wrote:
> No reason to take the trip around CentroidX() and CentroidY().
> Just simply use the Centroid() function to get a point
When did that one slip into the toolbox? I've got to start reading the
"What's New" sections of the documentation when new releases escape.
Just about every day it seems I learn something new... about MapBasic!

Eric Blasenheim

unread,
Jan 20, 2011, 7:02:49 PM1/20/11
to MapInfo-L
Gee Bill, Centroid() has been there a really long time. You just made
me crank up version 2.1 to make sure it was in that version! Yes!

Another nice thing about doing this the way David and Peter noted is
that you don't get into all the errors about not having the Set
Coordsys statement right. As you are never asking for coordinate
value, what your current Coordsys is set to is irrelevant.
You can even coordinate conversion without doing anything.
Professional will ensure the conversion occurs when writing the new
point object to a table of a different coordinate system.

Eric Blasenheim
PBBI (MapInfo)

Bill Thoen

unread,
Jan 20, 2011, 8:07:08 PM1/20/11
to mapi...@googlegroups.com
Now there's a reverse easter egg! So it's been there lying like a toad
in the mud, hiding out while CentroidX and Y and one of my own functions
did all its work since the dawn of the Windows 95 epoch? And how did you
get ver 2.1 to even run? Doesn't it require a 20-year old OS with 64K
RAM and 5-inch floppy drives?

Well, that's why I hang out here. I learn so much all the time. The one
who taught me MapBasic never said a word about it. I think I'm going to
download the actual manual and see what else I've missed. Got a version
for the Kindle yet?

Zery

unread,
Jan 20, 2011, 8:20:17 PM1/20/11
to mapi...@googlegroups.com
If something like this is happening, there's a function that we missed that can make life easier, what is the suggestion, rebuild your own library or just live with it and try to remember the left behind function on future coding?

Regards,
Zery

Eric Blasenheim

unread,
Jan 20, 2011, 9:09:07 PM1/20/11
to MapInfo-L
2.1 or any of the 16-bit versions won't run on a 64-bit version of
Windows. There is no 16-bit emulator for the 32-bit emulator running
on 64-bit. But any 32-bit version of Windows runs the old versions
pretty well. There are a lot of old apps out there and compatibility
layers in Windows. Of course, since it was meant to run on the systems
at the time, its footprint is tiny. It loads in about 4 seconds.
No Kindle version but there's got to be a way to load a PDF, isn't
there?
Eric
> GISnet -www.gisnet.com<http://www.gisnet.com/>
> 1401 Walnut St., Suite C
> Boulder, CO 80302303-786-9961begin_of_the_skype_highlighting              303-786-9961      end_of_the_skype_highlightingtel
> 303-443-4856 fax
> bth...@gisnet.com- Hide quoted text -
>
> - Show quoted text -

Bill Thoen

unread,
Jan 20, 2011, 10:46:43 PM1/20/11
to mapi...@googlegroups.com
On Fri, Jan 21, 2011 at 01:20:17AM +0000, Zery wrote:
> If something like this is happening, there's a function that we missed
> that can make life easier, what is the suggestion, rebuild your own
> library or just live with it and try to remember the left behind function
> on future coding?

I'd say do a reasonable bit of homework first, and if you don't find the
solution, then ask around. Places like here are pretty good. If you're
still stuck for an answer, then see if you can solve the problems through
other approaches. Then if that fails, consider the buy, borrow(copy) or
build "triangle", probably in that order. Building your own library is good
for a lot of reasons, but it's the most expensive route to take. Really.
There's the benefits of owning your own tools, and the freedom to do what
you like with them, and of course on your next job(s) you can build better
and faster if have some good, well-tested procedures already coded. But it
costs plenty to build, and if time is money to you think twice before going
that way.

DYI has its traps for those who don't use good judgement allocating
time to build a good library. It takes more time than you think, and you
really need to be honest with yourself as to the reasons why you're Doing It
Yourself. In the long run, I think it pays off to have your own library,
but I also buy tools because sometimes the client has a need and wants
something NOW and wants it done right. And if you add up the cost and
divide by your hourly salary, and note that you're also buying from someone
who knows the problems in the task you have, and also has many hours of
testing and debugging behind their product, and you can have it
now, sometimes that way is better.

But if my favorite software package doesn't do what I'd like, I bear if I
can't find/remember any alternatives, or I do something to acquire what I
need, and I'm seldom sure whether I did the right thing. But if the job
gets done, meets the spec, client is happy and I get paid, then I can
afford to build a little more time. And so it grows...


Zery

unread,
Jan 20, 2011, 10:58:49 PM1/20/11
to mapi...@googlegroups.com
As always Bill, a comprehensive answer, thank you. It gives me another point of view how to organized everything (read: programming task) and even my self :-)

Thank you
Regards,
Zery

-----Original Message-----
From: Bill Thoen <bth...@gisnet.com>
Sender: mapi...@googlegroups.com
Date: Thu, 20 Jan 2011 20:46:43
To: <mapi...@googlegroups.com>
Reply-To: mapi...@googlegroups.com
Subject: Re: [MI-L] Re: Create a new point layer from centroids of

Peter Horsbøll Møller

unread,
Jan 21, 2011, 1:34:58 AM1/21/11
to mapi...@googlegroups.com
Bill,
Maybe we should consider a weekly mail describing "a function that you probably didn't know existed in MapBasic" :-)

Yes, reading the What's new section of the MapBasic User Guide is a good start - unfortunately the Documentation section on our web page only has the documentation back to v9.0.

Peter Horsbøll Møller
Pitney Bowes Business Insight - MapInfo


2011/1/21 Bill Thoen <bth...@gisnet.com>
--

Peter Horsbøll Møller

unread,
Jan 21, 2011, 1:46:08 AM1/21/11
to mapi...@googlegroups.com
Zery,
If you have build your library properly, you could change your library to take use of this new or improved function and in this way imrpove your library.

I agree with Bill, building your own library will take time but in the long run, I think it's worth the while. Also remember you do not need to build it all in one day, but everytime you create a new function in an application of yours, consider if this could be useful in other applications as well. If so, add it to the library instead of adding it to an internal module of the current application.

There are certain functions that you just can't live without, like IsThisTableOpen(), GetMeAListOfOpenTables(), GetMeAListOfOpenWindows() and so on.

Also consider using templates if your text editor supports this. This will make it easier to create a new application, if you have a template that  with one click create the base module iwht a main procedure, some basic menus, an aboutbox, and a EngProgram procedure. This template also could contain includes for a number of your most used modules in your library.

I have templates for a new main module, a new extra module, a new procedure, a new function, a loop, a dialog etc. This makes it easy to add this to my project and when I add it, it looks similar to those I already have.

Peter Horsbøll Møller
Pitney Bowes Business Insight - MapInfo


2011/1/21 Zery <zer...@gmail.com>

Bill Thoen

unread,
Jan 21, 2011, 10:12:49 AM1/21/11
to mapi...@googlegroups.com
On 1/20/2011 11:34 PM, Peter Horsb�ll M�ller wrote:
> Bill,
> Maybe we should consider a weekly mail describing "a function that you
> probably didn't know existed in MapBasic" :-)
>
> Yes, reading the What's new section of the MapBasic User Guide is a
> good start - unfortunately the Documentation section on our web page
> only has the documentation back to v9.0.
>
I've got it locked in long-term memory now and backed up deep in the
monkey level of my brain. So all I need to do now is take out a banana
when I want to remember some function and my inner chimp will be bedside
himself hauling out memories as fast as he can, 'til he gets the right
one and I eat the banana.

Bill Thoen

unread,
Jan 21, 2011, 10:43:50 AM1/21/11
to mapi...@googlegroups.com
On 1/20/2011 11:46 PM, Peter Horsb�ll M�ller wrote:
> There are certain functions that you just can't live without, like
> IsThisTableOpen(), GetMeAListOfOpenTables(), GetMeAListOfOpenWindows()
> and so on.
>
Ha! those were some of the first functions I wrote for mine too! Then
there's IsThisLayerOnThrMap() and then the first general purpose
error-handling module, which gets replaced by a different one just about
every time I use it, because there's no one way to handle all error
management. But the very first one I wrote solved a problem we don't
have any more. Do you remember the semi-colon delimited string list?
That used to be the only way to populate a popup menu or list box
control before arrays became a part of the MapBasic language. The
problem was how to get the text content of such a list when the user's
response to a multi-line dialog control came back as "3", for example.
So the first thing I wrote that I knew would be used over and over again
was a parser for those lists.

> Also consider using templates if your text editor supports this. This
> will make it easier to create a new application, if you have a
> template that with one click create the base module iwht a main
> procedure, some basic menus, an aboutbox, and a EngProgram procedure.
> This template also could contain includes for a number of your most
> used modules in your library.
>

If you editor doesn't support these then you need a new editor. But you
can always maintain a set of empty documents that contain the skeleton
of modules, functions, and so on, but it's a lot more convenient to have
right there in your eidtor. Either way, pre-written, tested, and
bug-free code is money in the bank. There's a lot of redundant material
in a MapBasic program and any technique that speeds up typing, and
doesn't make mistakes is usually worth using.

Zery

unread,
Jan 21, 2011, 1:22:57 PM1/21/11
to mapi...@googlegroups.com
I'm using Notepad++ and Edge.J.P MapBasic syntax highlighting as the editor, with some extra plugin the editor now ALMOST like using UltraEdit. I do have a template, library, snippets and so on... Yup I did get (copy) some of the function in my library from here. Those function you mentioned, it sit tight in the library :-).

MI-L surely the best place to hang out to get MI and MB information, that's the first reason why I get myself a Blackberry, I don't want to miss even a single mail from here.


Regards,
Zery

-----Original Message-----
From: Bill Thoen <bth...@gisnet.com>
Sender: mapi...@googlegroups.com
Date: Fri, 21 Jan 2011 08:43:50
To: <mapi...@googlegroups.com>
Reply-To: mapi...@googlegroups.com
Subject: Re: [MI-L] Re: Create a new point layer from centroids
ofpolygonlaying retaining information from polygon layer

mark909

unread,
Jan 23, 2011, 2:33:46 PM1/23/11
to MapInfo-L
Awesome thank you David works a treat!
Reply all
Reply to author
Forward
0 new messages