If a post belongs to two categories how do I choose the main category?

If by “main” category you mean the category that is used to create the permalink, the default is to use the category with the lowest ID. You can access the post also with an URL that contains another category, but the rewrite_canonical() function will kick in and redirect you to the “canonical” URL with the “main” category.

However, if you hook into the get_permalink() function and return a URL based on another category, the canonical rewriter will notice this and it won’t redirect.

So you will need to create a UI in the post creation screen to select the “main” category, and hook into post_link to create URLs with this category.